Reputation: 2141
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.
Upvotes: 1
Views: 824
Reputation: 119031
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.
Upvotes: 4