Database Reference
In-Depth Information
var
migrationMappingModel :
NSMappingModel
if
let
mappingModel = mappingModel {
migrationMappingModel = mappingModel
}
else
{
var
error :
NSError
?
migrationMappingModel =
NSMappingModel
.
inferredMappingModelForSourceModel
(
from, destinationModel: to, error: &error)!
}
// 3
let
destinationURL = storeURL.
URLByDeletingLastPathComponent
let
destinationName = storeURL.
lastPathComponent
+
"~"
+
"1"
let
destination =
destinationURL!.
URLByAppendingPathComponent
(destinationName)
println
(
"From Model:
\(from.
versionIdentifiers
)
"
)
println
(
"To Model:
\(to.
versionIdentifiers
)
"
)
println
(
"Migrating store
\(storeURL)
to
\(destination)
"
)
println
(
"Mapping model:
\(mappingModel)
"
)
// 4
var
error :
NSError
?
let
success =
migrationManager.
migrateStoreFromURL
(storeURL,
type:
NSSQLiteStoreType
,
options:
nil
,
withMappingModel:mappingModel,
toDestinationURL:destination,
destinationType:
NSSQLiteStoreType
,
destinationOptions:
nil
,
error:&error)
// 5
if
success {
println
(
"Migration Completed Successfully"
)
var
error :
NSError
?
let
fileManager =
NSFileManager
.
defaultManager
()
fileManager.
removeItemAtURL
(storeURL, error: &error)
fileManager.
moveItemAtURL
(destination, toURL:
storeURL, error:&error)
}
else
{
NSLog
(
"Error migrating
\(error)
"
)
}