问题描述
我有一个要存档的CLLocation
数据数组.应该使用NSUserDefaults
系统吗?否则,如何最好地存档CLLocation
数据?
I have an array of CLLocation
data that I would like to archive. Should the NSUserDefaults
system be used? Otherwise, how best to archive the CLLocation
data?
推荐答案
UserDefaults仅可以存储某些类型的数据,并且应该用于存储用户首选项信息,而不能存储任意应用程序状态数据.
UserDefaults can only store certain types of data, and should be used to store user preference information, not arbitrary application state data.
引用苹果文档:
更多信息此处.
如果您的CLLocation数据确实确实算作用户首选项信息(我不敢相信),则必须将CLLocation中的信息映射到与NSUserDefaults兼容的类型上.阅读有关NSUserDefaults的文档.
If your CLLocation data really does count as user preference info (which I'm not convinced of), you'll have to map the info inside CLLocation onto types that are compatible with NSUserDefaults. Read the docs for NSUserDefaults.
如果您的CLLocation数据不是用户首选项信息,而只是您需要保留的应用程序数据/状态,则有几种选择;您可以将其存储在核心数据中,也可以使用键控归档-例如,请参见本教程
If your CLLocation data isn't user preference info, but just application data/state that you need to preserve, you have a few options; you could store it in core data, or you could use keyed archiving - see this tutorial, for example.
这篇关于需要存档CLLocation数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!