assert migration chain when creating a data stack

This commit is contained in:
John Rommel Estropia
2015-07-09 08:08:11 +09:00
parent 4f3e679aa1
commit 9da323b0b8
2 changed files with 66 additions and 23 deletions

View File

@@ -53,14 +53,17 @@ public final class DataStack {
*/
public required init(modelName: String = applicationName, bundle: NSBundle = NSBundle.mainBundle(), migrationChain: MigrationChain = nil) {
CoreStore.assert(
migrationChain.valid,
"Invalid migration chain passed to the \(typeName(DataStack)). Check that the model versions' order is correct and that no repetitions or ambiguities exist."
)
let model = NSManagedObjectModel.fromBundle(
bundle,
modelName: modelName,
modelVersion: migrationChain.leafVersions.first
)
// TODO: assert existence of all model versions in the migrationChain
self.coordinator = NSPersistentStoreCoordinator(managedObjectModel: model)
self.rootSavingContext = NSManagedObjectContext.rootSavingContextForCoordinator(self.coordinator)
self.mainContext = NSManagedObjectContext.mainContextForRootContext(self.rootSavingContext)