alexrothenberg / motion-addressbook

MIT License
89 stars 30 forks source link

Undefined method 'map' for nil:NilClass when calling 'groups' on AddressBook object. #51

Closed ryanlntn closed 10 years ago

ryanlntn commented 10 years ago

When calling groups() on an AddressBook object I get the following error:

addr_book.rb:38:ingroups': undefined method map' for nil:NilClass (NoMethodError)

Tracing that back we have:

def groups
  ab.all_groups.map do |ab_group|
    AddressBook::Group.new(:ab_group => ab_group, :address_book => ab.ab)
  end
end

def all_groups
  ABAddressBookCopyArrayOfAllGroups(ab)
end

My understanding from the Apple docs is that ABAddressBookCopyArrayOfAllGroups() should return an array. What's going on here?

jmay commented 10 years ago

Documentation is not always to be trusted. I've been hunting down a bunch of issues of this sort, guess I missed this one (or possibly introduced it while fixing others). Are you seeing this on iOS6 or 7?

Simple fix is:

def all_groups
  ABAddressBookCopyArrayOfAllGroups(ab) || []
end

but I want to make sure its reproducible and we have proper test cases before I push out a patch.

ryanlntn commented 10 years ago

I'm seeing it on iOS7. I haven't been able to get the simulator to run for iOS6. You wouldn't happen to know anything about this error would you?

dyld: Library not loaded: /System/Library/Frameworks/MediaAccessibility.framework/MediaAccessibility
  Referenced from: /Users/ryanlntn/Library/Application Support/iPhone Simulator/6.0/Applications/3C081A97-2E91-4C00-82C1-4D4D11B6B81E/Obispo.app/Obispo
  Reason: image not found

I'm able to run the iOS6 simulator for other RubyMotion apps.

jmay commented 10 years ago

I should have asked if you were running XCode4 or 5. If you're on iOS7 then clearly you are on 5. I haven't been successful getting XCode5 to build an iOS6 app, so I switch between Xcode versions when switching targets.

That error is definitely my fault, it's apparently debris from an app that I'm building that uses the motion-addressbook gem. I don't understand how that stuff from an app could get into a gem. Investigating now. Perhaps I'm checking something into git that should be ignored.

jmay commented 10 years ago

Ryan, I still can't reproduce your errors. Could you please try a couple of things:

ryanlntn commented 10 years ago

Ah I see. RubyGems was referencing version 1.5.0. It works now that I'm pulling the latest version from Github.

jmay commented 10 years ago

That's a huge relief.