开发者

IPhone SDK - How to serialize ABRecord?

开发者 https://www.devze.com 2023-01-06 15:51 出处:网络
I\'m new in iPhone development, can you advice me how to serialize AdressBook records? I have read stackoverflow - How do I serialize 开发者_StackOverflow中文版a simple object in iPhone sdk, but I sti

I'm new in iPhone development, can you advice me how to serialize AdressBook records?

I have read stackoverflow - How do I serialize 开发者_StackOverflow中文版a simple object in iPhone sdk, but I still have questions: should I extend ABRecordRef? Is it possible? Or should I implement own class NSObject?

(similar question was on Mac forums and was left without answer)

Thank you!


ABRecord is an opaque C type. It is not an object in the sense of Objective-C. That means you can not extend it, you can not add a category on it, you can not message it. The only thing you can do is call functions described in ABRecord Reference with the ABRecord as a parameter.

You could do two things to be able to keep the information referenced by the ABRecord arround:

  1. Get the ABRecords id by ABRecordGetRecordID(). The ABRecordID is defined as int32_t so you can cast it to an NSInteger and store it wherever you like. You can later get the record back from ABAddressBookGetPersonWithRecordID () or ABAddressBookGetGroupWithRecordID(). But aware, the record could be changed or even deleted by the user or another app meanwhile.

  2. Copy all values inside the record to a standard NSObject subclass and use NSCoding or other techniques to store it. You will then of cause not benefit from changes or additions to the record the user could have made.

Of cause you can combine both approaches.

0

精彩评论

暂无评论...
验证码 换一张
取 消