Simple Migration Options for CoreData PersistentStoreCoordinator

If you change a scheme of your CoreData such as adding a new attribute, you can easily migrate it with options below.

do {
            try persistentStoreCoordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: [NSMigratePersistentStoresAutomaticallyOption: true , NSInferMappingModelAutomaticallyOption: true])
        } catch {
            fatalError("Error migrating store: (error)")
        }

Leave a Reply