简体   繁体   English

使用Core Data将Thrift结构保存到文件

[英]Save a Thrift struct to a file using Core Data

I was wondering if there is a nice way to save a Thrift struct to a file/SQLite using iOS's Core Data. 我想知道是否存在使用iOS的Core Data将Thrift结构保存到文件/ SQLite的好方法。

One way is to do the mapping manually between the Thrift declaration and Entities in Core Data, but that's a lot of work and is not very easy to maintain. 一种方法是在Thrift声明和Core Data中的实体之间手动进行映射,但这是很多工作,而且维护起来也不是很容易。

A second idea is to save the Thrift as a binary data field in an Entity. 第二个想法是将Thrift保存为实体中的二进制数据字段。

Is there a more elegant way? 有没有更优雅的方式? Eg, a library that takes in a Thrift and takes care of this business? 例如,一个使用Thrift并负责这项业务的图书馆?

Thank you, Silviu 谢谢西尔维

You can use NSValue to wrap structures. 您可以使用NSValue包装结构。 In turn, NSValue objects can be stored in a transformable attribute. 反过来, NSValue对象可以存储在可转换属性中。

However, if you want to search or manipulate the contents of struct within Core Data, then you should model the struct as an entity and provide a method in the custom subclass to return the struct if needed. 但是,如果要在Core Data中搜索或操作struct的内容,则应将结构建模为实体,并在自定义子类中提供方法以在需要时返回该结构。

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

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