Objective-C best choice for saving data

瘦欲@ 提交于 2019-12-12 04:31:08

问题


I'm currently looking for the best way to save data in my iPhone application; data that will persist between opening and closing of the application. I've looked into archiving using a NSKeyedArchiver and I have been successful in making it work. However, I've noticed that if I try to save multiple objects, they keep getting overwritten every time I save. (Essentially, the user will be able to create a list of things he/she wants, save the list, create a few more lists, save them all, then be able to go back and select any of those lists to load at a future date.)

I've heard about SQLite, Core Data, or using .plists to store multiple arrays of data that will persist over time. Could someone point me in the best direction to save my data? Thanks!


回答1:


Core Data is very powerful and easy to use once you get over the initial learning curve. here's a good tutorial to get you started - clicky




回答2:


As an easy and powerful alternative to CoreData, look into ActiveRecord for Objective-C. https://github.com/aptiva/activerecord




回答3:


I'd go with NSKeyedArchiver. Sounds like the problem is you're not organizing your graph properly.

You technically have a list of lists, but you're only saving the inner-nested list.

You should be added the list to a "super" list, and then archiving the super-list.

CoreData / SQL seems a bit much from what you described.




回答4:


Also you can try this framework. It's very simple and easy to use. It's based on ActiveRecord pattern and allow to use migrations, relationships, validations, and more.

It use sqlite3 only, without CoreData, but you don't need to use raw sql or create tables manually.

Just describe your iActiveRecord and enjoy.




回答5:


You want to check out this tutorial by Ray Wenderlich on Getting started with CoreData. Its short and goes over the basics of CoreData.

Essentially you only want to look at plists if you have a small amount of data to store. A simple list of settings or preferences. Anything larger than that and it breaks down specifically around performance. There is a great video on iTunesU where the developers at LinkedIn describe their performance metrics between plists and CoreData.

Archiving works, but is going to be a lot of work to store and retrieve your data, as well as put the performance challenge on your back. So I wouldn't go there. I would use CoreData. Its extremely simple to get started with and if you understand the objects in this stack overflow question then you know everything you need to get going.



来源:https://stackoverflow.com/questions/7122587/objective-c-best-choice-for-saving-data

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