views:

279

answers:

1

I'm trying to use ABRecordRef within an NSMutableArray, but it doesn't seem to work. I know that ABRecord is a C class, but I thought that ABRecordRef was the work around Objective-C class that allowed me to use it with NSObjects. What do I need to do to make this work?

+2  A: 

What do you mean by "Not Working"? As in, you get compile or run-time errors?

As I noted in the response to the other poster, you can't use the Objective-C API on the iPhone (There also is no true ABrecord class to brdge to).

Generally it's a really good idea with the address book stuff on the iPhone to copy out elements you are interested in, and save the copied values off in something like a dictionary. If you need to save all the elements, you have to have code that reads every value as defined in the AddressBook.h header file, there's no API way to generically walk the records.

Also remember that at any time, the user might change the address book if they quit your app and come back - so be careful about what you change after they relaunch the app if you are storing values!!

Kendall Helmstetter Gelner
I get compilation warnings and runtime errors.Which dictionary? NSDictionary?
chaostheory
Yep, NSDictionary - something like I use that so I can save off a name under the key "@name". For things like the phone numbers or email addresses, I save those off as an array of more dictionaries, each dictionary holding a "@email" and @"label" key to hold the individual values.
Kendall Helmstetter Gelner
Thanks for the hint, I thought that struct is bridgeable, even though there's no class. It could have been, had Apple taken the same code for the iPhone as in Core Foundation.
Georg
yeah that's one thing that's really messing me up gs, the IPhone SDK is similar but different to OSX. I'll give what Kendall says a run.
chaostheory
There's probably more going on in the bridge class than it looks like, though honestly it seems like it would be easy enough to port the whole Objc Address Book overlay.... The devil of it is that you can compile the OS X code for the simulator so it's easy to use a class the phone doesn't have.
Kendall Helmstetter Gelner