CoreData model not compiled

Hi,

I'm trying to bundle an xcdatamodel in a swift executable package.

For some reason without adding anything to my Package.json, SPM copies the xcdatamodel file from Sources/MyPackage/Resources/MyDataModel.xcdatamodel to the target bundle's root without compiling it to momd..

I tried to enforce it by providing a resources process parameter:

.target(
            name: "mtb-video",
            dependencies: ["mtbUI", "TimecodeKit"],
            resources: [
                .process("Resources/MTBData.xcdatamodel")
            ]

By trying to find how SPM decided to copy the xcdatamodel verbatim I looked at the build files and the description.json contains my data model in the copyCommands dict.

image

So I tried everything again and no matter what it's always part of the copy commands ignoring my process instruction.

Does anyone have a clue?

Thanks

Environment:
macOS 10.15
Swift 5.3
NOT using XCode on purpose

Only Xcode supports Core Data models, there is no way to use them without Xcode.

1 Like

Thanks even as a custom command line build process? I do have XCode for the SDKs etc.. I just don't use it for compiling.

My idea would be:

  • Make SPM not copy the source xcdatamodel (putting it out of the target source folder works.)
  • Manually compile xcdatamodel to momd

So this is doable with this command, I now need to figure out how to properly move it to the app bundle

/Applications/Xcode.app/Contents/Developer/usr/bin/momc \
--action generate \
--swift-version 5.0 \
--sdkroot $SDK_ROOT \
--macosx-deployment-target 10.15 \
--module mtb-video \
MTBVideo.xcdatamodel \
CoreDataGenerated/MTBVideo