-
Evolve your Core Data schema
Learn how you can cleanly migrate Core Data schemas after updating your app, and breeze through data model changes. We'll show you how you can take advantage of built-in migration tools to keep your data storage up to date, and let Core Data analyze your schema to infer data model migrations. We'll also provide best practices, help you tackle tough migration challenges, and discover how Core Data schemas can interact with CloudKit to support easy migrations in the cloud.
To get the most out of this session, we recommend being familiar with Core Data schemas and data types, and have a basic understanding around syncing Core Data databases with CloudKit.Recursos
Vídeos relacionados
WWDC23
WWDC22
-
Buscar neste vídeo...
-
-
6:16 - Migrate your Core Data schema
import CoreData let storeURL = NSURL.fileURL(withPath: "/path/to/store") let momURL = NSURL.fileURL(withPath: "/path/to/model") guard let mom = NSManagedObjectModel(contentsOf: momURL) else { fatalError("Error initializing managed object model for URL: \(momURL)") } let coordinator = NSPersistentStoreCoordinator(managedObjectModel: mom) do { let opts = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true] try coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: Optional<String>.none, at: storeURL, options: opts) } catch { fatalError("Error configuring persistent store: \(error)") }
-