R.Swift + Multiple targets (widget, app clip ...)
Hey everyone, I'm struggling with the proper setup of the project where I use R.Swift and have multiple targets:
- Main iOS app
- App Clip
- Widget
I have files with R.Swift generated strings, images, colors and I'd like to share them across those targets.
enum Foo {
case a,b,c
var image: UIImage? {
switch self {
case .a:
return R.image.aImage()
case .b:
return R.image.bImage()
case .c:
return R.image.cImage()
}
}
}
What is the best way to do that? Should those targets use the single R.generated file, or every target should have its own file (with a different name?)? How should run script phases look like? I'd really appreciate any tips and guides on how to do that. Trying various setups I hit the wall with errors like:
Cannot find 'R' in scope
Multiple commands produce...
Cycle dependencies between targets...
Thanks!
The same question
You can setup R.swift to generate a separate R.generated file for each target. Create a Build Phase for each target, that generates a separate file at a separate location.
If needed, by passing —accessLevel public, the generated R struct will be public and can be used from a different target.