Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice to export core data entities

I need to export a few entities with its relationships in order to import it in other iOS device. For example:

A.relationship1 <------>> B.relationship1 (one to many)
B.relationship2 <-------> C.relationship1 (one to one)

Is there a way to serialize/deserialize (or other methods) to export/import "easily" a fragment of the core data model (objects and its relationships fetched by a fetched results controller? By serializing all the data pack (NSData or something), deserializing and inserting it to the context (importing).

Please point me in the right direction. Thanks in advance.

like image 837
Samui Avatar asked Apr 16 '12 21:04

Samui


1 Answers

The best way for you, i think,is convert your Core Data objects to JSON,save it,and then decode it back.

Here is absoluetley great working code of both encoding and decoding by Marcus Zarra

JSON and Core Data on the iPhone

like image 108
Nikita Pestrov Avatar answered Oct 22 '22 05:10

Nikita Pestrov