Join Todd Perkins for an in-depth discussion in this video Saving data to user defaults, part of Building a Note-Taking App for iOS 8.
- One of the ways to save data in iOS is to user defaults.…User defaults enable you to save data to persistent storage,…as long as it's simple data.…In other words, numbers and strings, and of course arrays…of numbers and strings or dictionaries,…with numbers and strings inside them.…So let's look at how to do that.…Inside of my note class, right below my init method,…I am going to create a method…to convert our notes into a dictionary.…
This will enable us to easily save…the data to persistent storage using user defaults.…So we'll call this dictionary,…and it's going to return an NSDictionary.…So we'll create a dictionary shorthand…by typing some square brackets.…The way to declare a shorthand dictionary…in Swift, is you write first the key.…The data type of our key is going to be a string,…and we'll call this first one note,…and the value is after a colon.…So note the string, and then after the colon,…note the value of the note property.…
So we're just taking our property name,…which is note, and then having that be the key,…
Each of these courses helps you build 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 with iOS 8, and compare your results with the Android and Windows Phone courses to learn about the differences and similarities of these mobile 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 or user defaults
- Understanding screens and storyboards
- Controlling transitions between views
- Connecting the controller to the data
- Creating, editing, and deleting notes