Created
November 4, 2017 19:38
-
-
Save barbaramartina/89f4eb77f27d81201578269cd8f4a0a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example to show how to check if core data can infers a mapping model by itself | |
// do not forget to add the .momd to you model object package!!!! | |
// https://developer.apple.com/documentation/coredata/nsmappingmodel/1506468-inferredmappingmodelforsourcemod | |
// SWIFT 4 | |
if let previousModelURL = Bundle.main.url(forResource: "YOURMODELNAME.momd/YOURMODELVERSION 2", withExtension: "mom"), | |
let previousModel = NSManagedObjectModel(contentsOf: previousModelURL), | |
let currentModelURL = Bundle.main.url(forResource: "YOURMODELNAME.momd/YOURMODELVERSION 3", withExtension: "mom"), | |
let currentModel = NSManagedObjectModel(contentsOf: currentModelURL) { | |
do { | |
let inferredModel = try NSMappingModel.inferredMappingModel(forSourceModel: previousModel, | |
destinationModel: currentModel) | |
// do the check here! | |
} catch { | |
// process error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment