Join John Nastos for an in-depth discussion in this video Storing and retrieving data from NSUserDefaults, part of Building an iOS Address Book App.
- [Voiceover] Now it's time to dig into implementing…NSUserDefaults in our code…in order to add persistence between launches.…Because the custom class Person…isn't one that NSUserDefaults can store automatically,…I'll need to make some adjustments to the class.…First, I'm going to make sure that it implements…the NSCoding protocol.…This is what will let the system know…that the class knows how to encode and decode itself…using a key value store…that will represent the object when saved.…
Secondly, Person will also need to inherit from NSObject,…which is the basic objective C object,…to make this functionality work.…Now that the object is implementing NSCoding,…I need to make sure that it implements…the correct methods and constructors…to conform to that protocol.…First, I'll write the encodeWithCoder method.…This is what the system will call…when it's time to store the object.…All I need to do here is make sure that each value…that I want stored,…which in this case are the instance variables,…like first name, last name, et cetera,…
Build the project step-by-step and then use what you've learned to explore your own app ideas.
- Creating the project in Xcode
- Using Auto Layout to design the UI
- Attaching the interface to the code
- Creating the data model, including a Person class
- Adding stored data to the UI
- Displaying a contact's address with MapKit
- Linking contact info to other iOS apps
- Adding persistence
- Working with table views
- Writing tests
- Preparing to publish the app in the App Store