IPhone SDK - How to serialize ABRecord?
Asked Answered
T

1

5

I'm new in iPhone development, can you advice me how to serialize AdressBook records?
I have read stackoverflow - How do I serialize 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!

Tonetic answered 8/7, 2010 at 14:36 Comment(0)
S
12

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.

Saffron answered 8/7, 2010 at 15:12 Comment(2)
Thank you for answer, this brings understanding!Tonetic
very useful. I was struggling with a way of a person back after saving a copy into my apps core data. So this helped.Tab

© 2022 - 2024 — McMap. All rights reserved.