Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing ABRecordRef in Core Data

I would like to store a ABRecordRef in a 'Client' entity in core data.

I have read in apples documentation that ABRecordRef is a primitive C data type. As far as I am aware, you can only insert objects in core data. With this in mind, what is the best way to store it in core data?

I thought about converting it into a NSNumber for storage, but dont know how to convert it back to ABRecordRef for use.

I also thought I could just put it in a NSArray/NSSet/NSDictionary on its own just acting as a wrapper but didnt know if this was silly/inefficient/would even work.

Thoughts appreciated.

Many thanks

like image 469
Ben Thompson Avatar asked Dec 16 '22 03:12

Ben Thompson


1 Answers

In one of my apps I just stored the ABRecordGetRecordID() as a INT32 in the CoreData store (since an ABRecordID is a int32_t) and also stored the contact name in the CoreData store for quick display purposes. That way the Record information is stored in the AddressBook where it belongs and you have just stored a "pointer" to the record in your CoreData store.

You could then create handy wrapper accessors in your custom Client NSManagedObject that would wrap the C calls to the AB framework to suit your needs.

like image 101
Brent Priddy Avatar answered May 16 '23 06:05

Brent Priddy