如何使用Swift在我的iOS应用程序上存储持久数据? [英] How do I store persistent data on my iOS app using Swift?

查看:104
本文介绍了如何使用Swift在我的iOS应用程序上存储持久数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iOS应用程序,它将从事件的RSS源解析XML,并在表视图上显示每个事件的详细信息。每个活动都有标题,描述(可选),日期和时间。我能够使用NSXMLParser解析XML数据;但是,我不确定应该如何存储数据并使其在关闭应用程序后仍然存在。

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.

我读过我可以使用NSCoder来保存数据,但我不确定这是否是最好的前进路线。

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?

感谢任何帮助。

推荐答案

您有几种保留数据的选项。

You have several options for persisting data.


  • NSUserDefaults 适用于用户设置 - 少量数据。它们似乎不适合您的想法。

  • NSCoding 是存储结构化数据的一种很好的方法,没有开销一个数据库,但与核心数据相比, 很慢。

  • 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.

核心数据是苹果ORM,它非常强大,但不是那么容易包围。

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

我最近回答了类似问题,其中详细介绍了 NSCoding 带有完整的示例和一些可供进一步阅读的链接。

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

这篇关于如何使用Swift在我的iOS应用程序上存储持久数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆