Migrating from Core Data to SwiftData
Less than 1 minute
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
: thePersistentModel
protocol and@Model
macroNSPredicate
: the#Predicate
macroNSFetchRequest
:FetchRequest
NSFetchDescriptor
:FetchDescriptor
NSCompoundPredicate
: Has no equivalent yetNSSortDescriptor
:SortDescriptor
NSMigrationStage
:MigrationStage
NSEntityMigrationPolicy
:SchemaMigrationPlan
Most notably, Xcode’s model editor is no longer needed now – it’s all code.