iOS Persistence and Core Data

Storing Your App’s Data


大约 2 个月

6小时每周 (自主学习)




大约 2 个月

6小时每周 (自主学习)



Persisting data is a core skill for any iOS developer. This course will teach you two techniques for storing data to your device’s hard drive: the NSKeyedArchiver method and the more complex, but robust Core Data.

喜欢这门课程?加入“iOS 开发者”纳米学位,点此免费体验


Just like computers, your iPhone has two types of memory: main memory (RAM) and the hard drive. In all the apps you’ve written, you’ve interacted with RAM, but this memory is limited, and it’s important that the apps you design use it as efficiently as possible. To use the RAM efficiently it is important to be able to store data on the hard drive.

It is also important for your apps to maintain state when they are turned off. The apps you’ve built probably aren’t persistent, meaning that they don’t save their state to the device’s hard drive. As RAM is volatile, data is lost when the app stops running. In this course, you’ll learn how to persist the state of the device using NSKeyedArchiver and Core Data.


This course assumes extensive iOS experience. Specifically, you’ve built several apps, know how to use core iOS libraries, and are familiar with networking and MVC design principles. Introduction to iOS App Development with Swift, UIKit Fundamentals, and iOS Networking with Swift are good courses to take if you need to familiarize yourself with these concepts.

The course also assumes basic familiarity with git. Specifically, you will need to be able to clone git repositories and checkout branches specific to each lesson. How to Use Git & GitHub is a great option if you need to brush up on these skills.

You will need access to a Mac computer running OS X 10.9 or later. However, you do not need an iPad or iPhone to complete the activities. All exercises can be completed using the iOS simulator built into Xcode.





无需离开家门便能周游世界!凭借这款应用,你可以锁定地图上的某个位置,然后调出与该位置相关的 Flickr 图片。你将使用核心数据存储位置和图片。


Lesson 1: NSUserDefaults

In this lesson, you’ll learn about the memory applications for each state in an app’s life cycle. You’ll also learn to persist an app in the “not running” state using NSUserDefaults and the Documents Directory.

We’ll introduce you to the following iOS classes in this lesson:

  • NSUserDefaults
  • NSFileManager

Lesson 2: NSCoder/NSKeyedArchiver

In this lesson, you’ll learn to persist arrays and dictionaries to the Documents directory, and persist custom structs using a Keyed Archiver.

We’ll introduce you to the following iOS classes in this lesson:

  • NSKeyedArchiver
  • NSKeyedUnarchiver

We’ll also introduce you to the following protocol:

  • NSCoding

Lesson 3: Persistent Objects & Core Data

In this lesson, you’ll be introduced to the Core Data framework, Apple’s favorite framework for the model class. You’ll learn how Core Data manages its stack using a pre-built app, “Favorite Actors.”

We’ll introduce you to the following iOS classes in this lesson:

  • NSManagedObject
  • NSManagedObjectContext
  • NSFetchRequest

Lesson 4: Core Data from Scratch

In this lesson, you’ll learn how to create a Core Data stack from the ground up. You will also learn how to specify relationships between you your Core Data managed objects. By the end, you’ll be proficient enough to describe every element in a Core Data project.

We’ll introduce you to the following iOS classes in this lesson:

  • NSManagedObjectModel
  • NSPersistentStoreCoordinator

Lesson 5: Smart Architecture with Core Data

In this lesson, you’ll learn how Core Data relates to MVC design as Apple envisioned it. You will learn how to architect apps so that controller objects are notified whenever the data stored in Core Data changes, allowing the controllers to keep the views updated in ways that keep your code trim and extensible.

We’ll introduce you to the following iOS classes in this lesson:

  • NSFetchResultsController
  • NSFetchResultsControllerDelegate


Jason Schatz

Jason Schatz

Jason Schatz was a Java developer until he was charmed by the first iPhones. He has been developing apps as a consultant ever since. He enjoys writing and teaching software in equal measure, and thinks the transition to Swift will be excellent for both. He has a M.S. in Computer Science from U.C. Davis and is a faculty member at City College of San Francisco.