iOS上的Objective C数据缓存 [英] Objective C Data Caching on iOS
本文介绍了iOS上的Objective C数据缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从API中提取数据,然后使用它来构建我的数据对象。我想缓存此数据为未来。我一直存储从api在NSUserDefaults的字符串,然后重新解析它每次应用程序加载。这工作,但它真的似乎是错误的方式去。
I am pulling data from an API and then building out my data objects with it. I want to cache this data for the future. I have been storing the string from the api in NSUserDefaults and then re-parsing it each time the app loads. This works, but it really seems like the wrong way to go about it.
如何做到这一点?
推荐答案
这个问题的解决方案,没有正确的方式做到这一点。以下几个热门选项是:
There are many different solutions to this problem and there is no "right" way to do it. A few popular options are:
- 收集数据 - 苹果的持久性框架。非常高效,但更困难。
- SQLite - 快速,灵活,但只是骨骼。
- Plists - 基本上将文件写入磁盘,必须手动读写。
- NSUserDefaults - 最轻的键值选项。
- Core Data - Apple's framework for persistence. Very performant, but more difficult.
- SQLite - Fast and flexible, but bare bones.
- Plists - Basically writing a file to disk, you have to read and write manually.
- NSUserDefaults - The lightest weight "key-value" option.
我鼓励你阅读所有四个,看看哪一个最适合你。
I would encourage you to read up on all four and see which one works best for you.
这篇关于iOS上的Objective C数据缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文