Storing ABRecordRef in Core Data

淺唱寂寞╮ 提交于 2019-12-21 17:56:35

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/9353661/storing-abrecordref-in-core-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!