简体   繁体   English

在iOS4中存储配置的最佳方法是什么?

[英]What's the best way to store configuration in iOS4?

I'm going to write recipe application. 我要编写食谱应用程序。 What's the best way to store configuration (list of recipes) in iOS4? 在iOS4中存储配置(配方列表)的最佳方法是什么? XML, JSON files, Core Data or something other? XML,JSON文件,Core Data或其他?

I'd use SQLite. 我会使用SQLite。 Although CoreData has a few advantages in retrieval it is a bit difficult to actually load your data into the data store. 尽管CoreData在检索方面有一些优势,但实际上很难将数据加载到数据存储中。 You can even use something like FMDB to wrap SQLite, if that makes things easier for you. 您甚至可以使用FMDB之类的方法包装SQLite,如果这样可以使您更轻松。

Since the recipes will be HTML, I'd just store them in a single column, with additional columns for the category, keywords, image BLOB, etc. I'd also include a column for storing the user's personal notes about each recipe. 由于配方将是HTML,因此我将它们存储在一个单独的列中,并在类别,关键字,图像BLOB等中添加其他列。我还将包括一个列,用于存储用户关于每个配方的个人注释。

If your recipes were more structured, I'd store them within the database as JSON, because I find XML a nuisance to deal with on iOS. 如果您的食谱结构更合理,我会将其作为JSON存储在数据库中,因为我发现XML在iOS上难以处理。

First of all this depends on where the data is initially stored. 首先,这取决于数据的最初存储位置。 Will your recipe app be self-consistent, that is will it contain all receipts bundled in the app or will it download them from the network based on user interactions? 您的食谱应用程序是否会保持一致,即包含应用程序中捆绑的所有收据,还是会根据用户交互从网络上下载它们? (eg searching for regional receipts, or seasonal receipts, and so on). (例如,搜索区域收据或季节性收据,等等)。

RECEIPTS FROM NETWORK (ONLINE APP) 来自网络的收据(在线应用程序)

In such case you will download the receipts from the network by request. 在这种情况下,您将根据要求从网络下载收据。 The best way to store them is leave them dynamically in memory while the app is running (memory cache). 最好的存储方式是在应用程序运行时将其动态保留在内存中(内存缓存)。 You will purge the memory cache as soon as there is some low memory pressure. 一旦内存不足,您将立即清除内存缓存。 Receipts loading will be lazy as if the receipt is in the memory cache it will be retrieved from it, if missing (because never loaded or purged) it will be retrieved from the network again. 收据的加载将是懒惰的,就像收据在内存缓存中一样,将从中检索它;如果丢失(因为从未加载或清除),则将再次从网络中检索它。 A great improvement can be achieved by setting up a network disk cache (using standard Cocoa caching system or some open source framework such as MKNetworkKit or ASIHTTPRequest). 通过设置网络磁盘缓存(使用标准的Cocoa缓存系统或某些开源框架,例如MKNetworkKit或ASIHTTPRequest),可以实现巨大的改进。 In such case the receipt will be retrieved in this order: memory cache, disk cache, network. 在这种情况下,将按以下顺序检索收据:内存缓存,磁盘缓存,网络。 The app will then work offline (only for receipts that have been loaded yet), and you will never need to worry about receipts storage as the disk cache will take care of this. 该应用程序随后将脱机工作(仅适用于已加载的收据),并且您将不必担心收据存储,因为磁盘缓存将解决此问题。

BUNDLED RECEIPTS 收据收据

Typically a receipts memory graph could be slightly more complex than a simple "array" of receipts. 通常,收据存储图可能比简单的“收据”数组稍微复杂。 You can have a receipts table ("entity"), an ingredients table, a restaurants table if you link this receipt to restaurants that offer it, a photography table and so on. 如果您将此收据链接到提供收据的餐厅,摄影表等,则可以具有收据表(“实体”),食材表,餐厅表。 In such case the complexity of the object graph is such that CoreData is the better solution. 在这种情况下,对象图的复杂性使得CoreData是更好的解决方案。 You will not care of the persistent store (typically SQLite and managed by CoreData framework). 您无需关心持久性存储(通常为SQLite,并由CoreData框架进行管理)。 You may need to pre-load the CoreData store at start-up, this can be done using a "dev app" that reads the original data source (xml, json, csv), creates the managed objects and save them in the CoreData storage. 您可能需要在启动时预加载CoreData存储,这可以使用“开发应用”来完成,该应用读取原始数据源(xml,json,csv),创建托管对象并将其保存在CoreData存储中。 Then you will get the resulting file and you will save it in your bundle. 然后,您将获得结果文件,并将其保存在捆绑软件中。 An extra complexity may arrive if you want to keep your app up to date with new receipts taken from the network, without releasing an app update each time. 如果您想使您的应用程序与网络上的新收据保持同步,而不每次都发布应用程序更新,则可能会带来额外的复杂性。 In such case the best flow is: - put the CoreData storage in the app bundle - at first start up, copy it in the app sandboxed documents area (or app Library/Caches if you don't want to add extra backup space to the user; then protect this area against OS cache automatic cleaning) - each time your app retrieves new receipts from the network (automatically or from In App Purchase) parse the received data (xml, json, csv, ...) and save it in your CoreData storage. 在这种情况下,最好的流程是:-将CoreData存储放入应用程序捆绑包中-首次启动时,将其复制到应用程序沙盒文档区域(如果您不想向应用程序库/缓存中添加额外的备份空间,则将其复制到应用程序库/缓存中)。用户;然后保护此区域免受OS缓存的自动清理)-每次您的应用从网络上(自动或从应用内购买中)检索新的收据时,都会解析收到的数据(xml,json,csv等)并将其保存在您的CoreData存储。

NOTE 注意

This suggestion is not coming from guesses but real experience. 这个建议不是来自猜测,而是真实经验。 I have developed several receipt apps, especially online ones. 我开发了几个收据应用程序,尤其是在线收据应用程序。

恕我直言,我会使用SQLITE,因为它易于使用,并且您始终可以访问组织良好的数据。

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

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