简体   繁体   中英

How to convert CoreData object to NSData

I need to convert a CoreData object into NSData (to send it to another app via GameKit).

I tried using NSKeyedArchiver and NSKeyedUnarchiver, but it seems archiving and unarchiving CoreData objects is tricker than normal objects.

I've been digging through the CoreData documentation, but haven't found any clue, yet. Can someone point me to the proper doc or give me a hint how to do this?

Thanks in advance.

You can add a method to each of your objects that require it that returns a dictionary containing all of the keys and values that you need to store/send. NSDictionary natively supports archiving so once you have the dictionary everything is as usual. This should probably be less code and more flexible than trying to retrofit archiving into the managed object subclasses directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM