Skip to main content

Migrating from Core Data to SwiftData

Less than 1 minuteSwiftArticle(s)bloghackingwithswift.comcrashcourseswiftswiftdataxcodeappstore

Migrating from Core Data to SwiftData 관련

SwiftData by Example

Back to Home

Migrating from Core Data to SwiftData | SwiftData by Example

Migrating from Core Data to SwiftData

Updated for Xcode 15

If you’ve used Core Data before, many of the classes and concepts you know and love map pretty much directly to their SwiftData equivalents, albeit with simpler names and always without the NS prefix.

Here’s a list to get you started, with Core Data names followed by SwiftData names:

  • NSPersistentContainer: ModelContainer
  • NSPersistentCloudKitContainer: ModelContainer with iCloud enabled.
  • NSManagedObjectContext: ModelContext
  • NSManagedObject: the PersistentModel protocol and @Model macro
  • NSPredicate: the #Predicate macro
  • NSFetchRequest: FetchRequest
  • NSFetchDescriptor: FetchDescriptor
  • NSCompoundPredicate: Has no equivalent yet
  • NSSortDescriptor: SortDescriptor
  • NSMigrationStage: MigrationStage
  • NSEntityMigrationPolicy: SchemaMigrationPlan

Most notably, Xcode’s model editor is no longer needed now – it’s all code.


이찬희 (MarkiiimarK)
Never Stop Learning.