Join Todd Perkins for an in-depth discussion in this video Loading data from user defaults, part of Building a Note-Taking App for iOS 8.
- Now that we've saved our data to User Defaults,…let's look at loading data from User Defaults.…So I'm in Note.swift, and I'm going to scroll down…right below the "saveNotes" method,…and I'm going to create another class method…called "loadNotes".…So in here we're going to load the data…for the User Defaults and then we're going to do…the opposite of what we did in "saveNotes".…We're going to take that raw dictionary…with values and keys,…and we're going to apply it to notes…and repopulate our "allNotes" array.…
So we'll start by creating a variable called "defaults",…and this is going to be of the type NSUserDefaults.…I'm just doing this to conserve line space…so we don't need a special variable to hold this.…So I'm going to set this equal to…"NSUserDefaults.standardUserDefaults",…so now I can just reference that whole long code…with this short code in my variable here.…So now I'll create a variable called "savedData",…and this is what's going to grab that data…from our User Defaults,…this is going to be an array of NSDictionaries,…
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