NSUserDefaults还是存储大型数组时的其他内容? [英] NSUserDefaults or something else when storing large arrays?

查看:80
本文介绍了NSUserDefaults还是存储大型数组时的其他内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将JSON读取到内存中对象的应用程序。我有一个代表用户的对象,然后是一组自定义对象。这个数组通常是20-50个对象,但在极少数情况下最多可以达到7-800个对象。



我已经阅读了一些有关此主题的文章,但发现很难选择,由于我要做的只是在本地缓存此内容,仅此而已,这样我就可以从服务器获取更少的内容。



我可以看到三种解决方案:


  1. NSUserDefaults 。不确定大型阵列会如何影响应用性能


  2. CoreData / MagicalRecord 。看起来不错,但有点复杂


  3. 带有NSCoding / Decoding的Plist


  4. 自定义解决方案


我倾向于使用NSUserDefaults或Plist,因为它似乎最简单,并且我只想在应用程序启动/存在时读取和读取内存。但是,在存储这么多对象时,我应该了解诸如性能或应用启动时间之类的任何问题吗?还有其他使用MagicalRecord的原因吗?



指针倍受赞赏。



编辑:添加了plist / NSCoding选择

解决方案

早上好,我的朋友,U有一个很好的问题,让我们了解使用它更好: / p>


  • NSUserDefaults-通常用于例如某些设置,帐户的定义,是否定义应用程序,通常是易于存储的全局变量并打开了对数据的访问


  • Plist-不需要复杂查询的少量数据,无需编辑大量字段也适合存储,问题是plist中序列化时的数组和字典是递归传递的,也就是说,每个地块或其他容器中的字典上只包含一层外壳。从这里开始,对内容的限制也随之而来:仅允许序列化的类型。


  • Coredata / SQLite-需要结构化查询的大量数据,我想想,您首先要问一个问题:为什么我不应该在这里使用Coredata。稍微了解一下,您就会了解Coredata非常适合存储任何类型和数量的数据。


  • MagicalRecord-用于简化工作的库核心数据,它的优点(清理我的核心数据相关代码,允许进行清晰,简单的单行提取,当需要优化请求时仍允许修改NSFetchRequest)如果不这样做,我不建议使用了解Coredata的工作原理




结果:如果实际上您需要存储一些密钥价值,并且您不想打扰核心数据知识,而且您没有时间学习,请对数据使用plist。如果您想存储更困难和更大容量的东西-仅coredata。我个人建议使用coredata,您坚信它既简单又方便,只需要花费时间。



使用plist信息



使用核心数据信息



祝您好运,做出正确的选择,我不明白为什么有人不赞成您的问题,这个问题真的很好,并且是具体的答案,请向我+1 ...


I have an app that reads JSON into in-memory objects. I have one object representing the User and then an array of custom objects. This array is ususally 20-50 objects but can be up to 7-800 in rare cases.

I've read some threads about this, but find it hard to pick, since all i want to do is cache this locally, nothing more, so that i can fetch less from the server.

I can see three solutions:

  1. NSUserDefaults. Not sure how app performance is affected by large array

  2. CoreData / MagicalRecord. Seems nice but a bit complicated

  3. Plist with NSCoding/Decoding

  4. Custom solution.

I am leaning towards NSUserDefaults or Plist since it seems easiest, and i only want to read to and from memory when the app starts/exists. However, is there any issue i should know about, like performance or app startup time when storing so many objects? Is there other reasons for using MagicalRecord?

Pointers much appreciated.

EDIT: Added the plist/NSCoding choice, had forgotten.

解决方案

Good day, my friend, U have a good question let's understand that it is better to use:

  • NSUserDefaults - usually use for example for definition of some Settings, Accounts, whether definitions the application, generally a global variable for easy storage and access to data was opened

  • Plist - Small amount of data that do not need complex query, editing not a large number of fields is suitable for storage also, The matter is that arrays and dictionaries at serialization in a plist are passed recursively, that is, only one more level of an enclosure on each massif or the dictionary in other container turns out. From here also restrictions on contents follow: only the types which are giving in to serialization.

  • Coredata/SQLite - Big amount of data which need Structured Query, I think, you have to ask the question "why I shouldn't use Coredata here" first of all. And having a little understood you will understand that the Coredata is ideally suited for storage of any types and volumes of data.

  • MagicalRecord - library for simplification of work with core data, its advantages(Clean up my Core Data related code, Allow for clear, simple, one-line fetches,Still allow the modification of the NSFetchRequest when request optimizations are needed) I don't recommend to use if you don't understand as the Coredata works

RESULT : If in fact you need to store some key value and you don't want to bother with knowledge of core data and you have no time for studying, use plist for your data. If you want to store something more difficult and more volume - only coredata. I personally recommend to use coredata, you are convinced that it is easy and convenient, it is necessary to spend time only.

use plist info

use core data info

Good luck, make a right choice, I don't understand why someone down vote your question, the question really good and on it is the concrete answer, +1 from me...

这篇关于NSUserDefaults还是存储大型数组时的其他内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆