ios iPhone 应用程序的本地存储
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6725428/
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
Local storage for iPhone app
提问by Gang Wu
I want to develop an application. The functionality is similar to RSS feed reader. Read a XML from web service and display them in a table view. But I have some problems to deal with the local storage. I do not need to store all the history records since it takes a lot of storage. But I do want to store dozens of newest records so the user can really see something even when the new data is loading or there is no network connection. What should I do? Should I use Coredata or other methods?
我想开发一个应用程序。该功能类似于 RSS 提要阅读器。从 Web 服务读取 XML 并将它们显示在表视图中。但是我在处理本地存储时遇到了一些问题。我不需要存储所有历史记录,因为它需要大量存储。但我确实想存储几十条最新记录,这样即使在加载新数据或没有网络连接时,用户也能真正看到一些东西。我该怎么办?我应该使用 Coredata 还是其他方法?
回答by dtuckernet
There are several ways to implement this storage within your iOS project (3 that I will mention here):
有几种方法可以在你的 iOS 项目中实现这个存储(我将在这里提到的 3 种):
Core Data - Core Data is extremely powerful, and it could certainly handle your use case. There is some overhead in setting up your data model. You can read about Core Data here: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/index.html
SQLite Database - Your core data implementation would probably use SQLite as its persistent store. However, you also can use SQLite directly. This allows you to handle the data however you want, but it also requires a lot of overhead to get it up and running in the manner you mentioned above. This can be a good solution but, I don't think it is a good fit for your project. http://www.techotopia.com/index.php/An_Example_SQLite_based_iOS_4_iPhone_Application
Property List - Property lists are very easy to implement within a project for both reading and writing data. You can read more about property lists here: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html
Core Data - Core Data 非常强大,它当然可以处理您的用例。设置数据模型有一些开销。您可以在此处阅读有关核心数据的信息:https: //developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/index.html
SQLite 数据库 - 您的核心数据实现可能会使用 SQLite 作为其持久存储。但是,您也可以直接使用 SQLite。这允许您根据需要处理数据,但也需要大量开销才能以上述方式启动和运行。这可能是一个很好的解决方案,但我认为它不适合您的项目。http://www.techotopia.com/index.php/An_Example_SQLite_based_iOS_4_iPhone_Application
属性列表 - 属性列表很容易在项目中实现,用于读取和写入数据。您可以在此处阅读有关属性列表的更多信息:https: //developer.apple.com/library/content/documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html
Hope that helps.
希望有帮助。