Skip to content

feat: add support for CoreData source files #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

danieleformichelli
Copy link
Contributor

@danieleformichelli danieleformichelli commented May 28, 2025

I am migrating a big project to use Tuist and I'm looking at how to integrate xcdatamodeld and xcdatamodelmapping files. In the project I am migrating from, those files are all added in the Compile Source build phase and nothing in resources.
In Tuist:

  • I can't use Target.sources as they are not among the "whitelisted" sources
    Is there a reason why it's not allowed
  • If I use Target.coreDataModels I can only add xcdatamodeld and inner xcdatamodel which are added to BOTH sources and resources

This is why I'm updating the valid source extensions to include xcdatamodeld as well.

@pepicrft pepicrft requested a review from fortmarek May 28, 2025 16:23
@pepicrft
Copy link
Contributor

Don't forget to fix the linting issues :)

Copy link
Member

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I use Target.coreDataModels I can only add xcdatamodeld and inner xcdatamodel which are added to BOTH sources and resources

This sounds like a bug. That's not the behavior I'm seeing in our coredata fixture where we do use Target.coreDataModels to integrate those. In the fixture, the data models only end up in the compile sources build phase:
image

Would you mind providing a sample that reproduces the issue?

I don't think we should allow those models to be valid source files over using the explicit property we have for these.

@danieleformichelli danieleformichelli marked this pull request as draft May 29, 2025 08:13
@danieleformichelli
Copy link
Contributor Author

I don't think we should allow those models to be valid source files over using the explicit property we have for these.

Thanks, I'll try to follow that then.

The difference between my project and the PR is that I am adding those to a static framework, so I see the files both in the generated. bundle, and in the source build phase of the framework, but maybe it's fine, I'll try with that 👍

One thing I can't find is how to add xcmappingmodel files. Also in the fixture I can see there is one, but I can't see it referenced in the generated Xcode project.
In my (pre-Tuist) project I see it goes in the Compile Sources section as well, but I guess it's similar to the xcdatamodeld. Do I need to add support for it in the Target.coreDataModels property?

@fortmarek
Copy link
Member

The difference between my project and the PR is that I am adding those to a static framework, so I see the files both in the generated. bundle, and in the source build phase of the framework, but maybe it's fine, I'll try with that 👍

Let us know – if it doesn't work, we can change how core data models are integrated in static frameworks.

One thing I can't find is how to add xcmappingmodel files. Also in the fixture I can see there is one, but I can't see it referenced in the generated Xcode project.

I am not too familiar with .xcmappingmodel files – but I think they don't have the same considerations as xcdatamodeld files and it should be fine to add them directly as resources or sources. We currently allow .xcmappingmodel files to be only resources but xcodegen adds those to sources. Is there a strong reason to choose one over the other? I am honestly not sure. But I can see some logic in those being in the sources build phase, the same way that's the default for .xcmodeldatad files. If that's the case, we can add .xcmappingmodel here. We need to keep it also in validResourceCompatibleFolderExtensions in order not to break existing projects.

@danieleformichelli
Copy link
Contributor Author

The difference between my project and the PR is that I am adding those to a static framework, so I see the files both in the generated. bundle, and in the source build phase of the framework, but maybe it's fine, I'll try with that 👍

Let us know – if it doesn't work, we can change how core data models are integrated in static frameworks.

One thing I can't find is how to add xcmappingmodel files. Also in the fixture I can see there is one, but I can't see it referenced in the generated Xcode project.

I am not too familiar with .xcmappingmodel files – but I think they don't have the same considerations as xcdatamodeld files and it should be fine to add them directly as resources or sources. We currently allow .xcmappingmodel files to be only resources but xcodegen adds those to sources. Is there a strong reason to choose one over the other? I am honestly not sure. But I can see some logic in those being in the sources build phase, the same way that's the default for .xcmodeldatad files. If that's the case, we can add .xcmappingmodel here. We need to keep it also in validResourceCompatibleFolderExtensions in order not to break existing projects.

From what I can see, it should work in both sources and resources, I'll try to stick to the currently Tuist implemented way (resources) and see how it goes.
I have opened this PR to update the ios_app_with_coredata fixture, and I'll close this PR, thanks for the guidance! 🙏

@danieleformichelli danieleformichelli deleted the feat/coredata-sources branch May 29, 2025 09:29
@fortmarek
Copy link
Member

Thanks, we can reopen this if it turns out having the xcmappingmodeld is a requirement :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants