[英]Including data in iOS application bundle
So, I have a new requirement to include some data in my iOS app bundle (instead of having it downloaded via API call), because the data is quite large, and won't change often. 因此,我有一个新的要求,即将某些数据包含在我的iOS应用程序捆绑包中(而不是通过API调用下载),因为这些数据很大,并且不会经常更改。
My current setup is: 我当前的设置是:
What I'm looking for is a best approach to bundle the data in my app (which will save me from having to download the "initial" data set which will be large in size). 我正在寻找的是将数据捆绑到我的应用程序中的最佳方法(这将使我不必下载较大的“初始”数据集)。
I know, I have an option to include the initial data set in my bundle in a json file, then have this loaded into my object model and archived, but I was wondering if I can generate an NSArchive file (which contains my initial data set) and have it included in my app bundle? 我知道,我可以选择将初始数据集包含在包中的json文件中,然后将其加载到我的对象模型中并进行存档,但是我想知道是否可以生成NSArchive文件(其中包含我的初始数据集) )并将其包含在我的应用程序包中?
Any recommendations are welcome. 欢迎任何建议。
Thanks. 谢谢。
If you are using NSCoding
compliant classes for your objects, then I suggest writing and reading the data using [NSKeyedArchiver archiveRootObject:toFile:]
and [NSKeyedUnarchiver unarchiveObjectWithFile:]
, respectively. 如果您对对象使用与
NSCoding
兼容的类,则建议分别使用[NSKeyedArchiver archiveRootObject:toFile:]
和[NSKeyedUnarchiver unarchiveObjectWithFile:]
写入和读取数据。 The data can be saved as an XML or a binary property list by using the setOutputFormat
method. 可以使用
setOutputFormat
方法将数据另存为XML或二进制属性列表。
For more info, check Apple's Archives and Serializations Programming Guide and NSHipster's article on NSCoding . 有关更多信息,请查阅Apple的“ 存档和序列化编程指南”和NSHipster 在NSCoding上的文章 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.