简体   繁体   English

导出核心数据实体的最佳做法

[英]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. 我需要导出一些具有关系的实体,以便在其他iOS设备中导入它。 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). 有没有办法序列化/反序列化(或其他方法)以“轻松”导出/导入核心数据模型的片段(由获取的结果控制器提取的对象及其关系?通过序列化所有数据包(NSData或其他)) ,反序列化并将其插入上下文(导入)。

Please point me in the right direction. 请指出我正确的方向。 Thanks in advance. 提前致谢。

The best way for you, i think,is convert your Core Data objects to JSON,save it,and then decode it back. 我认为,最好的方法是将Core Data对象转换为JSON,保存,然后将其解码。

Here is absoluetley great working code of both encoding and decoding by Marcus Zarra 这是由Marcus Zarra编写和解码的absoluetley伟大的工作代码

JSON and Core Data on the iPhone iPhone上的JSON和核心数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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