xcode 在 iPhone/iPad 上缓存数据的正确方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5352627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:33:42  来源:igfitidea点击:

Correct way caching data on iPhone/iPad

objective-cxcodeioscaching

提问by Thizzer

What is the correct way to cache file and/or string data on ios? Is CoreData useful for this, or is there a better wat of doing this?

在 ios 上缓存文件和/或字符串数​​据的正确方法是什么?CoreData 对此有用吗,或者有更好的方法吗?

What is the best method to cache for performance and what for caching for persistence for any amount of data?

为了性能而缓存的最佳方法是什么,对于任何数量的数据来说,为了持久性而缓存的最佳方法是什么?

I can't seem to find any nice Apple docs about this subject.

我似乎找不到关于这个主题的任何好的 Apple 文档。

回答by Neha Agrawal

There are many different solutions to this problem and there is no "right" way to do it. A few popular options are:

这个问题有很多不同的解决方案,没有“正确”的方法来解决这个问题。一些流行的选项是:

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.

Core Data - Apple 的持久性框架。性能非常好,但更难。SQLite - 快速而灵活,但只是骨架。Plists - 基本上是将文件写入磁盘,您必须手动读取和写入。NSUserDefaults - 最轻量级的“键值”选项。我鼓励你阅读所有四个,看看哪一个最适合你。