I have created new version of CoreData model and migrated existing one to it. Application works without any issues on iOS 9+, but for iOS 9 and 10 I am getting this error:
It seems to be the problem with optimized model versions on < iOS 11. Just use unoptimized .mom model version instead (CafeManager v2.mom
).
Here's how I fixed it:
public func managedObjectModel() -> NSManagedObjectModel {
let omoURL = modelBundle.url(forResource: name, withExtension: "omo", subdirectory: modelDirectoryName)
let momURL = modelBundle.url(forResource: name, withExtension: "mom", subdirectory: modelDirectoryName)
guard var url = omoURL ?? momURL else { fatalError("model version \(self) not found") }
// Use unoptimized model version < iOS 11
if #available(iOS 11, *) {} else { if let momURL = momURL { url = momURL} }
guard let model = NSManagedObjectModel(contentsOf: url) else { fatalError("cannot open model at \(url)") }
return model
}
If you're thinking, I want my speed, why would I use something unoptimized, read this answer.