Seeding a Core Data Persistent Store

6 Episodes

Episode 1

05:11

Three Strategies

Seeding an application with data can be helpful for a wide range of reasons, including unit and performance testing. As a developer, seeding an application is simply convenient during development. You want to see and experience what the application feels like with data in it, without having to enter that data in by hand. How does the application perform with hundreds or thousands of records? What is the user experience like?

Episode 2

09:52

Hard-Coding Seed Data

Seeding a Core Data persistent store with hard-coded seed data is fast and easy. The application we'll be seeding with data in this episode is Notes, the application we build in Core Data Fundamentals. Download the starter project of this episode if you'd like to follow along.

Episode 3

08:34

Seeding Data Asynchronously

We successfully seeded the Core Data persistent store with hard-coded seed data in the previous episode. While the implementation works fine, it isn't perfect. Seeding the persistent store takes place on the main thread. We invoke the seed() method in the viewDidLoad() method of the NotesViewController class and we insert the managed objects into the main managed object context of the Core Data manager.

Episode 4

08:12

Avoiding Duplicates

Every time we launch Notes, the persistent store is seeded with data. That's not what we want as it results in duplicates. In this episode, you learn how to easily avoid duplicates and how to start with a clean slate if you decide you no longer need seed data.

Episode 5

08:21

Loading Seed Data From a File

Hard-coding seed data is quick and easy, but it's not my preferred solution. Loading seed data from a file is a strategy I like more. The idea is simple. You include a file with seed data in the application bundle. The file is loaded at runtime and its contents parsed. The contents is used to seed the persistent store with data.

Episode 6

05:45

Loading Seed Data From a Remote Server

In the previous episode, you learned how to load seed data from a file in the application's bundle. It's a common option that isn't that hard to implement. Once you've laid the groundwork, though, the seed data can come from anywhere. Let me show you what changes we need to make to seed the persistent store with data fetched from a remote server.