Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barbaramartina/89f4eb77f27d81201578269cd8f4a0a3 to your computer and use it in GitHub Desktop.
Save barbaramartina/89f4eb77f27d81201578269cd8f4a0a3 to your computer and use it in GitHub Desktop.
// 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