77

I'm getting some of these prints in my console while running my application from Xcode 6 in my iPhone 6 with iOS 9 beta 5:

CoreData: Failed to load optimized model at path '/var/mobile/Containers/Bundle/Application/0000000B-BDBC-0000-000B-0000FB00000B/Distribution.app/database.momd/database.omo'

I cound't find something related to this, does anyone have some clue about this message?

Glauco Neves
  • 3,345
  • 1
  • 21
  • 36
  • 2
    I'm seeing a similar message using Xcode 6, but only when deploying to an iOS 9 device or sim. I do not see it when running any iOS on a device or a sim when using the Xcode 7 beta. So, given that iOS 9 is still in beta, my guess is that is a bug specific to the Xcode 6 iOS 9 combination. I'm going to ignore it for now. My app works as expected, so I'm not going to spend any time looking into this until I see the release candidate versions of iOS 9/Xcode 7. – Tony Adams Sep 08 '15 at 20:22
  • 6
    I'm also getting this with Xcode 7 GM. Any clue what this error message is about? – Buju Sep 15 '15 at 13:42
  • 2
    same with xcode 7 & iOS 9 – Tatarasanu Victor Sep 18 '15 at 13:34
  • what is the verdict on this issue? i've gone through every single post on the topic and no one seems to know what the problem is? has anyone made any headway on this? – kneuben_studdard Sep 24 '15 at 02:15
  • 1
    same problem is coming for GoogleMaps – Nullify Sep 24 '15 at 14:59
  • I’m having sam issue. Using Core Data in my app and DragonMobile’s SpeechKit. – Vakas Oct 01 '15 at 07:12
  • 2
    Getting this error on a new project upon starting to use xcode 9 (original schema created with xcode 8). – lal Sep 18 '17 at 19:56
  • Anyone know how it was solved for GoogleMaps? – lal Oct 01 '17 at 06:36
  • 1
    Here's one [solution](https://stackoverflow.com/a/53973476/82813) you could try. – Brooketa Jan 11 '19 at 09:15

5 Answers5

13

I've run into this issue and did some digging around.

I've been building with Xcode 6.4 and it looks like previously core data only produced a .mom file in the MyApp.ipa momd directory. This screenshot is from a project that has seen several version of Xcode.

Notice all the older model versions only have a .mom file. I just created a new model version today and it has both a .mom and an .omo file.

enter image description here

It appears that Xcode 6.4 (and perhaps some of the beta 7.x versions as well) do not know how to load the optimized version of the data model because I also get the

2015-10-16 11:11:42.563 MyAppName[1767:599635] CoreData: Failed to load optimized model at path '/var/mobile/Containers/Bundle/Application/D887D60B-FB28-4059-8167-F573460D98F8/MyAppName.app/MyDataModel.momd/MyDataModel3_0Analytics.omo'

warning when compiling with 6.4. However, when compiling the app with the latest app store version of Xcode (7.0.1) I do not get that warning. I'm guessing that the reason Mahesh's solution is working is because re-writing the entire schema creates the .omo file the app is looking for in the app bundle.

The solution for me was to generate a new data model version in core data and then build with Xcode 7. It seems that creating a new model version creates the optimized model file. In my testing though, even with this file created Xcode 6.4 still throws the error. It wasn't till I tried it with Xcode 7.0.1 that the warning went away.

This is speculation but I think if you have an existing project and have not created a new data model version and build with Xcode 7 that the .omo file is missing, so it's throwing the warning because it cannot find the file. However if you've versioned your data model and build with Xcode 6.4 it seems that the earlier Xcode version doesn't do something correctly with the optimized version and it doesn't load it even if its there. These are just my observations though.

I verified that I had an optimized model (.omo file) to load by doing the following: 1. archive your project 2. change the .ipa extension to .zip 3. expand your zip file 4. click on the "payload" folder and right click (or cmd click) on the app bundle in the folder and select "Show Package Contents". 5. click on the .momd directory, you should see all of your available managed object models there.

If all you have is .mom files and no .omo files then the warning makes complete sense, the app is unable to open a file that does not exist.

In my testing it seems like the warning was informational only. I never had any crashing because of it. It seems like core data may try to load the optimized model first, and if that fails fall back to the regular .momd model. This is merely my speculation though.

I'm not sure if everything here is entirely correct, this is just what I've observed so far in trying to debug this. If anyone else can contribute any more info I welcome your input.

digitalHound
  • 4,044
  • 22
  • 26
  • "In my testing it seems like the warning was informational only. I never had any crashing because of it." I'm having the same experience: I get the warning from Xcode 6, but everything works fine. I'm a bit scared to ship the app to the App Store with this warning still there, and I can't build it with Xcode 7... are we sure this is only a warning and no crashes will happen? – cdf1982 May 28 '16 at 08:40
  • 1
    I've been building with Xcode 7 so I haven't experienced the error anymore, but I didn't get any crashes from it in the version I shipped with Xcode 6. If you want to track any crashes that occur I'd recommend the fabric/crashlytics framework by Twitter. – digitalHound May 31 '16 at 03:34
4

I ran into this problem this morning. Did a small hack to get it running. I think it's got something to do with versioning mismatch but I'm not sure.

Anyhow, if you're loading a momd-file, just append a "/[filename].mom" to the NSURL to get it working.

In my case, I was loading the file Countly.momd and ended up doing this:

// Original loading
NSURL modelURL = [[NSBundle bundleForClass:[CountlyDB class]] URLForResource:@"Countly" withExtension:@"momd"];

// Small hack
modelURL = [modelURL URLByAppendingPathComponent:@"Countly.mom"];

Update: I was using a POD that used CoreData. Removing the pod and adding the source etc. from repo directly made the problem go away.

So it might be a pod-issue.

DiAvisoo
  • 173
  • 1
  • 1
  • 8
  • 2
    Hey - this is unclear to me and probably a ton of other readers. Can you explain the process of removing the pod and adding the source from the repo (where to get it, what to do, etc.). This bug is a big problem and this post seems to be the only thing out there where you did something that worked for you. If you could elaborate, we would appreciate it. – kneuben_studdard Oct 02 '15 at 13:49
  • 9
    Yeah seriously. I get error using GoogleMaps' pod and this happens - /GoogleMaps.bundle/GMSCacheStorage.momd/Storage.omo' – durazno Oct 03 '15 at 07:40
  • do you use MagicalRecord? Could this be related to MR + CocoaPods? – Buju Oct 05 '15 at 10:48
  • 1
    This answer is FALSE. The issue has nothing to do with pod. Do not waste your time trying this one out! – durazno Oct 06 '15 at 05:08
  • @durazno can you please explain why "this issue has nothing to do with pod" ? Because I just ran into it by extracting app's core to another pod, and coredata model goes there too. – ReDetection Aug 01 '16 at 05:50
  • @ReDetection Sorry I do remember having this issue and then fixing it somehow but do not remember how.. this was long time ago and all I can remember is that the fix was incredibly simple and stupid... – durazno Aug 04 '16 at 17:00
  • This makes the app to crash. – puru020 Aug 04 '16 at 19:57
  • 1
    @DiAvisoo's "small hack" has saved my life. I'm not having this pod issue you guys were talking about (I'm from the future in 2017). But I was trying to add backward compatibility in a Core Data app created in Xcode 9 for a iOS 9.3+ application. The swift 3 version of DiAvisoo's "small hack" solved my "big" problem: {code}let ios9modelURL = modelURL?.appendingPathComponent("Countly.mom"){code}. – Rob Oct 04 '17 at 16:51
4

After long search, it was just like this:

public lazy var persistentContainer: NSPersistentContainer = {

    var modelURL = Bundle(for: type(of: self)).url(forResource: "Model", withExtension: "momd")!

    // ===> here you append the nameOfVersion.mom you created
    modelURL.appendPathComponent("Model 2.mom")
    let managedObjectModel = NSManagedObjectModel(contentsOf: modelURL)
    let container = NSPersistentContainer(name: "ModelFile", managedObjectModel: managedObjectModel!)

    container.persistentStoreDescriptions.first?.shouldInferMappingModelAutomatically = false

 ...
brahimm
  • 636
  • 1
  • 9
  • 26
3

I found a solution for this. I rewrote the whole schema, and when I run the code I got rid of those warnings from core data.

I suggest please take back-up before you try this.

Hope it helps you.

Mahesh
  • 1,472
  • 1
  • 9
  • 16
0

I want to answer to people who ran into this when was writing own pod which has own CoreData models. Probably, you've put your model definition to the bundle (that's good), but you search for the momd file in the wrong bundle.

Let's say you have defined your bundle in podspec like this:

'MYPodBundle' => [
    'Model/*.{xcdatamodeld,xcdatamodel}'
]

Then you should first find this bundle, and then locate your model inside it.

NSURL *bundleURL = [[NSBundle bundleForClass:[MYEntity class]] URLForResource:@"MYPodBundle" withExtension:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
NSString *modelPath = [bundle pathForResource:@"MYCoreDataModel" ofType:@"momd"];
NSManagedObjectModel *managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]];

So you can continue creating CoreData stack.

//This may be a bit offtopic because you weren't writing own pod, but your answer is on google's top.

ReDetection
  • 2,706
  • 1
  • 19
  • 39