R.swift icon indicating copy to clipboard operation
R.swift copied to clipboard

R.Swift + Multiple targets (widget, app clip ...)

Open ondrejkorol opened this issue 3 years ago • 1 comments

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!

ondrejkorol avatar Apr 28 '22 17:04 ondrejkorol

The same question

MatusevichMaxim avatar Jul 27 '22 13:07 MatusevichMaxim

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.

tomlokhorst avatar Nov 11 '22 22:11 tomlokhorst