How do I store persistent data on my iOS app using Swift? [closed]

我怕爱的太早我们不能终老 提交于 2019-12-01 08:14:25

问题


I'm developing an iOS app that is going to parse XML from an RSS feed of events and display the details of each event on a table view. Each event has a title, a description (optional), a date and a time. I am able to parse the XML data using NSXMLParser; however, I am not sure how I should store the data and make it so that it persists after the app is closed.

I have read that I can use NSCoder to persist the data but I am not sure if this is the best route forward.

Does anyone have any ideas or suggestions as to what I could do?

Any help is appreciated.


回答1:


You have several options for persisting data.

  • NSUserDefaults are meant for user settings - small amounts of data. They seem unsuitable for what you have in mind.
  • NSCoding is quite a good way to store structured data without the overhead of a database, yet it is slow in comparison to core data.

  • Core Data is Apples ORM, which is quite powerfull but not as easy to wrap your head around.

I answered a similar question recently, which goes into more detail regarding NSCoding with a complete example and some links for further reading.



来源:https://stackoverflow.com/questions/35762561/how-do-i-store-persistent-data-on-my-ios-app-using-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!