Standalone "mom" models are not detected in the bundle #89

Closed
opened 2025-12-29 18:22:46 +01:00 by adam · 6 comments
Owner

Originally created by @andriichernenko on GitHub (Oct 5, 2016).

Extension of the compiled CoreData model file CoreStore tries to find on initialization is hardcoded as momd (see NSManagedObjectModel+Setup.swift):

@nonobjc
    internal static func fromBundle(_ bundle: Bundle, modelName: String, modelVersionHints: Set<String> = []) -> NSManagedObjectModel {

        guard let modelFilePath = bundle.path(forResource: modelName, ofType: "momd") else {

            CoreStore.abort("Could not find \"\(modelName).momd\" from the bundle. \(bundle)")
        }
        // ...

However, in some cases the model file has extension mom, which means that CoreStore is unable to find the model and fails.

Originally created by @andriichernenko on GitHub (Oct 5, 2016). Extension of the compiled CoreData model file CoreStore tries to find on initialization is hardcoded as `momd` (see `NSManagedObjectModel+Setup.swift`): ``` @nonobjc internal static func fromBundle(_ bundle: Bundle, modelName: String, modelVersionHints: Set<String> = []) -> NSManagedObjectModel { guard let modelFilePath = bundle.path(forResource: modelName, ofType: "momd") else { CoreStore.abort("Could not find \"\(modelName).momd\" from the bundle. \(bundle)") } // ... ``` However, in some cases the model file has extension `mom`, which means that CoreStore is unable to find the model and fails.
adam added the wontfix label 2025-12-29 18:22:46 +01:00
adam closed this issue 2025-12-29 18:22:46 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Oct 6, 2016):

Hi

The momd and mom files are different things. The momd file is actually a container that contains all version models, and each model version data are in their respective mom files. See the lower part of the NSManagedObjectModel+Setup.swift's fromBundle(...) method:

        // ...
        var modelVersionFileURL: NSURL?
        for modelVersion in modelVersions {

            let fileURL = modelFileURL.URLByAppendingPathComponent("\(modelVersion).mom", isDirectory: false)

This part iterates all mom files from inside the momd directory.

@JohnEstropia commented on GitHub (Oct 6, 2016): Hi The `momd` and `mom` files are different things. The momd file is actually a container that contains all version models, and each model version data are in their respective mom files. See the lower part of the `NSManagedObjectModel+Setup.swift`'s `fromBundle(...)` method: ``` swift // ... var modelVersionFileURL: NSURL? for modelVersion in modelVersions { let fileURL = modelFileURL.URLByAppendingPathComponent("\(modelVersion).mom", isDirectory: false) ``` This part iterates all mom files from inside the momd directory.
Author
Owner

@JohnEstropia commented on GitHub (Oct 6, 2016):

@deville Just to make sure, are you actually seeing a case where the .mom files are outside the .momd directory? If so, please tell which iOS version you are seeing this and if you have any idea how the file structure was changed.

@JohnEstropia commented on GitHub (Oct 6, 2016): @deville Just to make sure, are you actually seeing a case where the `.mom` files are _outside_ the `.momd` directory? If so, please tell which iOS version you are seeing this and if you have any idea how the file structure was changed.
Author
Owner

@andriichernenko commented on GitHub (Oct 6, 2016):

@JohnEstropia Yes, I actually had a mom file outside the momd.
I am using the latest versions of Xcode and iOS. The model files Xcode 8 creates have extension xcdatamodeld and they get compiled into momd. However, I copied the model from an old project, and it had extension xcdatamodel which was compiled into mom. So that's how I ended up with a separate mom file in the bundle.

@andriichernenko commented on GitHub (Oct 6, 2016): @JohnEstropia Yes, I actually had a `mom` file outside the `momd`. I am using the latest versions of Xcode and iOS. The model files Xcode 8 creates have extension `xcdatamodeld` and they get compiled into `momd`. However, I copied the model from an old project, and it had extension `xcdatamodel` which was compiled into `mom`. So that's how I ended up with a separate `mom` file in the bundle.
Author
Owner

@JohnEstropia commented on GitHub (Oct 6, 2016):

I think you should fix that on your side. I'm guessing you copied only the contents of your old xcdatamodeld without creating a new xcdatamodeld on your new project. You should put the xcdatamodel in a proper modeld container because versioning in Core Data (not necessarily CoreStore) is managed within that container.

@JohnEstropia commented on GitHub (Oct 6, 2016): I think you should fix that on your side. I'm guessing you copied only the contents of your old xcdatamodeld without creating a new xcdatamodeld on your new project. You should put the xcdatamodel in a proper modeld container because versioning in Core Data (not necessarily CoreStore) is managed within that container.
Author
Owner

@andriichernenko commented on GitHub (Oct 6, 2016):

@JohnEstropia Well, yes, I have fixed this, so no problem here.

I'm guessing you copied only the contents of your old xcdatamodeld without creating a new xcdatamodeld on your new project.

No, that's not the case, the xcdatamodel file I copied was not inside xcdatamodeld.

Since new Xcode versions always create models in container, I guess there's no point in modifying the existing model detection behavior. But maybe it would be nice to mention this somewhere in the docs, just in case somebody else runs into this.

@andriichernenko commented on GitHub (Oct 6, 2016): @JohnEstropia Well, yes, I have fixed this, so no problem here. > I'm guessing you copied only the contents of your old xcdatamodeld without creating a new xcdatamodeld on your new project. No, that's not the case, the `xcdatamodel` file I copied was not inside `xcdatamodeld`. Since new Xcode versions always create models in container, I guess there's no point in modifying the existing model detection behavior. But maybe it would be nice to mention this somewhere in the docs, just in case somebody else runs into this.
Author
Owner

@JohnEstropia commented on GitHub (Oct 6, 2016):

Okay, thanks. I wasn't familiar that older Xcode versions allowed creation of standalone xcdatamodels. Will see how to incorporate this in the README (although I feel theres a whole bunch of legacy behavior that CoreStore doesn't handle in the first place)

@JohnEstropia commented on GitHub (Oct 6, 2016): Okay, thanks. I wasn't familiar that older Xcode versions allowed creation of standalone `xcdatamodel`s. Will see how to incorporate this in the README (although I feel theres a whole bunch of legacy behavior that CoreStore doesn't handle in the first place)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore-JohnEstropia#89