Database Reference
In-Depth Information
func isVersion3() -> Bool {
return self == self . dynamicType . version3 ()
}
class func version4() -> NSManagedObjectModel {
return uncloudNotesModelNamed ( "UnCloudNotesDataModel v4" )
}
func isVersion4() -> Bool {
return self == self . dynamicType . version4 ()
}
To get the == comparison to work on two NSManagedObjectModel objects, add an
operator overload to the file. You'll need to add this outside of the class extension,
right in the global scope:
func ==(firstModel: NSManagedObjectModel ,
otherModel: NSManagedObjectModel ) -> Bool {
let myEntities = firstModel. entitiesByName as NSDictionary
let otherEntities = otherModel. entitiesByName as NSDictionary
return myEntities. isEqualToDictionary (otherEntities)
}
The idea here is simple: two NSManagedObjectModel objects are identical if they have
the same collection of entities, with the same version hashes.
Go back to the DataMigrationManager class declaration part of the file and add these
two helper methods:
func storeIsCompatibleWith(Model model: NSManagedObjectModel )
-> Bool {
let storeMetadata = metadataForStoreAtURL (storeURL)
return model. isConfiguration ( nil ,
compatibleWithStoreMetadata:storeMetadata)
}
func metadataForStoreAtURL(storeURL: NSURL ) -> NSDictionary ! {
var error : NSError ?
let metadata =
NSPersistentStoreCoordinator . metadataForPersistentStoreOfType (
NSSQLiteStoreType , URL: storeURL, error: &error)
if metadata == nil {
println (error)
}
return metadata
}
Search WWH ::




Custom Search