Migrations & Working with Core Data Instruction

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Working with SwiftData Migrations and Core Data

Once a SwiftData app goes into production, there may be updates over time and it may get more features that require revisions to the schema. Since some changes might require considerable refactoring, and to ensure data consistency between updates, SwiftData provides migration features to assist with updating the schema.

Migration

Imagine that you already published the GoodDog app to the App Store and you want to make changes to it. Perhaps you’ve made a few updates that required schema changes. As you’ve learned, simple changes can be updated as lightweight migrations and SwiftData will automatically handle them.

Schema Versioning - The Best Laid Plans

As you publish revisions to your app, many changes may be required to migrate users’ data. SwiftData has some built-in methods to help with the migrations.

// eg.
GoodDogSchema_V01_00_00.self,
GoodDogSchema_V01_01_00.self,
GoodDogSchema_V02_00_00.self
// eg.
MigrationStage.lightweight(
  fromVersion: GoodDogSchemaV01_00_00.self,
  toVersion: GoodDogSchemaV01_01_00.self
)
MigrationStage.custom(fromVersion:toVersion:willMigrate:didMigrate:)

Working with Core Data

In the second part of the lesson, you’ll learn about starting from a Core Data app that you’d like to change to SwiftData. Recall that CoreData is the precursor to SwiftData.

See forum comments
Download course materials from Github
Previous: SwiftData Migrations & Working with Core Data Next: SwiftData Migrations Demo