Pretty new to iOS dev, I feel I have a grasp of the basics. I was thinking through an app I would like to make and the steps involved, components needed... and I have no idea how to or what is the best method to save user input and retrieve it.
An example being (I don't plan to make this, but it illustrates what I want to know), say a simple to-do list, it has NSTableView that is populated from NSMutuableArray, to begin with it is blank as the user has added nothing. Once an item is added to the array, table reloads thanks to -reloadData. The item that is needed to-do is shown in the table. Great for this session... but not when the app is reopened.
I imagine I need to s开发者_JAVA技巧tore the array and then reload it when the app next initialises, is this correct?
Or is there any other better method?
If you're just starting out. The best way to go is to use Core Data to save and display your data. You'll thank me in the end.
http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/CoreData/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1
Tutorials
http://www.raywenderlich.com/934/core-data-tutorial-getting-started http://developer.apple.com/cocoa/coredatatutorial/index.html http://themikeswan.wordpress.com/2009/05/22/7/
Do a google search there are lots of resources.
In addition to Jordan's answer, mostly for completeness so you understand your options. You have at least another two options:
- Serialization using NSCoding (Archives and Serializations Programming Guide
- Property Lists (Property Lists Programming Guide)
Both these concepts are easier to understand than a proper relational database and are for simpler things worth considering. Especially since TODO lists are not likely to contain large amounts of data.
Property Lists is the easiest and most basic one in terms of functionality. It just lets you store primitives, but is good if your TODO list is just a collection of Strings.
Serilization using NSCoding is more powerful, but requires more work from the developer. With NSCoding you can create your own coders/decoders for your business objects that lets you persist the entire state. This would be good if you have your own Todo with a lot of properties, like title, priority, complete-by-date etc.
精彩评论