简体   繁体   English

在iOS应用程序包中包含数据

[英]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: 我当前的设置是:

  • Upon user login, I download the data (in json format) from the back-end DB 用户登录后,我从后端数据库下载数据(json格式)
  • Load it into my object model 将其加载到我的对象模型中
  • NSArchive it. NS将其存档。
  • On the next login, I unarchive and use the data (without requiring to download the whole data set again. Well, actually I still download data, but only the changed/new records will get downloaded). 在下一次登录时,我将取消存档并使用数据(无需再次下载整个数据集。嗯,实际上我仍然在下载数据,但是只有已更改/新记录会被下载)。

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.

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