Need to archive CLLocation data

前端 未结 4 697
迷失自我
迷失自我 2021-01-12 21:37

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

4条回答
  •  既然无缘
    2021-01-12 21:58

    UserDefaults can only store certain types of data, and should be used to store user preference information, not arbitrary application state data.

    To quote the Apple docs:

    The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an application to customize its behavior to match a user’s preferences. For example, you can allow users to determine what units of measurement your application displays or how often documents are automatically saved.

    More info here.

    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.

    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.

提交回复
热议问题