CoreData: annotation: Failed to load optimized model at path (Xcode 11 -> iOS 12)

I was able to solve the issue thanks to the hint in @ChaitanyaKhurana's comment above.

Here is the swift code I have implemented, replacing the original single line

let container = NSPersistentContainer(name: "ModelName")

Part of the code is needed to retrieve the model version string (from the .plist file located in the .momd package) in order to avoid having to update the code each time there is a new model version.

Please also note that the new/alternative code only executes on iOS versions prior to 13.0 as there is not issue on iOS 13.

let modelName = "ModelName"

var container: NSPersistentContainer!

if #available(iOS 13.0, *) {
    container = NSPersistentContainer(name: modelName)
} else {
    var modelURL = Bundle(for: type(of: self)).url(forResource: modelName, withExtension: "momd")!
    let versionInfoURL = modelURL.appendingPathComponent("VersionInfo.plist")
    if let versionInfoNSDictionary = NSDictionary(contentsOf: versionInfoURL),
        let version = versionInfoNSDictionary.object(forKey: "NSManagedObjectModel_CurrentVersionName") as? String {
        modelURL.appendPathComponent("\(version).mom")
        let managedObjectModel = NSManagedObjectModel(contentsOf: modelURL)
        container = NSPersistentContainer(name: modelName, managedObjectModel: managedObjectModel!)
    } else {
        //fall back solution; runs fine despite "Failed to load optimized model" warning
        container = NSPersistentContainer(name: modelName)
    }
}