Join Todd Perkins for an in-depth discussion in this video Working with data from user defaults, part of Building a Note-Taking App for iOS 7.
…Now we'll add something to our data model that…will allow us to save data to persistent storage.…We're going to save the data using…something called NSUserDefaults, which is a simple…dictionary that saves to persistent storage, and…can be accessed with one line of code.…So let's go down in Data.h, and declare another…class method that returns void and we'll call this saveNotes.…I'm going to copy this line of code, go to Data.m, and…scroll down to the bottom and paste this below all my other methods.…
Of course, I'll delete the semicolon and that curly braces.…And down here, we'll save the data to persistent storage.…To do that, type double square brackets,…and in the inner square brackets, type NSUserDefaults,…standardUserDefaults, and then in outer braces, setObject…and the object is going to be allNotes.…And for key, which I'm getting to, by pressing Tab…on my keyboard, is going to be kAllNotes, and that's it.…This single line of code saves all of our…notes to persistent storage and remains on the device…
These courses take you through building a complete mobile app from scratch; this installment uses the iOS SDK and Xcode to get the job done. Author Todd Perkins shows you how to create an Xcode project, lay out apps visually, connect UI elements to code, and save data to persistent storage. Start here, and compare and contrast your results with the other courses to learn about the differences and similarities of the platforms.
- Previewing the note-taking app's features
- Creating the Xcode project
- Using local data storage
- Creating a data class
- Saving data to a file
- Understanding screens and storyboards
- Creating and editing notes
- Controlling note display in a table view
- Deleting notes