How to convert ABRecordRef to NSData and NSData to ABRecordRef?

414 views Asked by At

I am trying to convert ABRecordRef to NSdata, but I am not sure how to achieve it. I want to save ABRecordRef to sqlite database and then after some time to add the same ABRecordRef to address book. I have tried this, but I am not sure whether it is the right way or not

 NSData *d = [[NSData alloc] initWithBytes:ref length:sizeof(ref)];

or something like this

NSData *data= (NSData *) ref;

it would be great if you showed me some way to convert it to NSdata and then back to ABRecordRef.

And is there any way I can store NSdata or directly ABRecordRef to sqlite database?

1

There are 1 answers

0
hverlind On

I think the same question is answered here.

Basically, what you are trying to do won't work because you are mixing plain C types with Objective-C types. Instead, what you could do is copy all the relevant properties of the ABRecord to an NSDictionary (or your own custom NSObject) and then serialize/deserialize that instead.