Database Reference
In-Depth Information
NSInferMappingModelAutomaticallyOption
:
false
]
}
if
storeModel.
isVersion1
() {
let
destinationModel =
NSManagedObjectModel
.
version2
()
migrateStoreAt
(URL:
storeURL
,
fromModel: storeModel,
toModel: destinationModel)
performMigration
()
}
else
if
storeModel.
isVersion2
() {
let
destinationModel =
NSManagedObjectModel
.
version3
()
let
mappingModel =
NSMappingModel
(fromBundles:
nil
,
forSourceModel: storeModel,
destinationModel: destinationModel)
migrateStoreAt
(URL:
storeURL
,
fromModel:storeModel,
toModel:destinationModel,
mappingModel: mappingModel
)
performMigration
()
}
else
if
storeModel.
isVersion3
() {
let
destinationModel =
NSManagedObjectModel
.
version4
()
let
mappingModel =
NSMappingModel
(fromBundles:
nil
,
forSourceModel: storeModel,
destinationModel: destinationModel)
migrateStoreAt
(URL:
storeURL
,
fromModel:storeModel,
toModel:destinationModel,
mappingModel: mappingModel
)
}
}
The steps are similar, no matter which version you start from:
•
Set up the options dictionary.
Remember, the version 1 model used a simple
lightweight migration, while the others used mapping model files. You need to
have different options dictionaries to account for this.
•
Set the destination model to the correct model version.
Remember, you're
only going “up” one version at a time, so from 1 to 2 and from 2 to 3.
•
For version 2 and above, also load the mapping model.