iphone - 我应该将 sqlite 数据库文件写入文档目录还是库/缓存吗?

标签 iphone ios5 xcode4.2 data-storage

我已经阅读了 Apple 的数据存储指南,并且对于应该将我在应用程序中创建的 sqlite 数据库文件保存在哪里感到非常困惑。即使应用程序处于离线模式,我也想读取 sqlite 文件。我读到创建的此类文件应该保存在库/缓存中,并设置“不备份”标志。请建议我执行相同操作的正确方法。

最佳答案

答案取决于数据库文件的创建方式:

According to the Data Storage Guidelines page :

  1. Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and will be automatically backed up by iCloud.

  2. Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory. Examples of files you should put in the Caches directory include database cache files and downloadable content, such as that used by magazine, newspaper, and map applications.

这对我来说似乎相对清楚:如果您的应用程序以编程方式创建某些内容或生成您想要保存的数据,请将其放入“缓存”文件夹中。如果是客户自己生成的独特内容(通过键盘输入或他们手动干预并执行的操作),请将其放入“文档”中。

“不备份”意味着文件永远不会发送到 iCloud,如果丢失,则必须从头开始重新创建(或重新安装)。

关于iphone - 我应该将 sqlite 数据库文件写入文档目录还是库/缓存吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11840318/

相关文章:

iphone - 如何将附加阴影添加到 uinavigationbar 和 uitoolbar

iphone - 核心数据通过两个描述符对数据进行排序

iphone - Cocoa 中的 XML-RPC 服务器

iphone - MkAnnotation 掉落动画 iOS 6

ios - 按钮的导航栏项目拉伸(stretch)图像

ios - 具有模态转场的 UISplitViewController 不旋转

iphone - 我的 iOS App 目标被误删

objective-c - 是否可以合并非 ARC 和 ARC 项目代码?

objective-c - 开发版本和 adhoc/release 之间有任何#define 或类似的区别吗?

xcode - 如何在 xcode 4.2 Storyboard中使用 UIPickerview?