How to add R.swift into XcodeGen project?

933 Views Asked by At

I'm experimenting with XcodeGen, and ran into a problem. I can't add "R.Swift" dependency. Not through SPM not through CocoaPods(

In the case of SPM, I don't understand how to add Run Build Tool Plug-in "RswiftGeneratesInternalResources (Swift)" into target/Build Phases

In the case of Cocoapods in R.generated.swift file an error appears "No such module 'Rswift'

Can anyone help me and show correct way how I can add R.swift into XcodeGen project?

4

There are 4 best solutions below

0
On

XcodeGen support Build Tool Plugin since 2.37.0.

packages:
  Rswift:
    url: https://github.com/mac-cain13/R.swift
    from: 7.4.0
targets:
  MyApp:
    ...
    dependencies:
      - package: Rswift
        product: RswiftLibrary
    buildToolPlugins:
      - plugin: RswiftGenerateInternalResources
        package: Rswift
    ...
0
On

Here is my project.yml. (with cocoapods, not spm.)

targets:
  MyApp:
    type: application
    platform: iOS 
    sources:
      - MyApp
    preBuildScripts:
      - name: Generate R.swift
        script: |
          "$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/MyApp/R.generated.swift"
        basedOnDependencyAnalysis: false

0
On

To add R.swift to Xcodegen using SPM, you can do the following steps:

  • Download released R.swift package from https://github.com/mac-cain13/R.swift/releases. Extract downloaded .zip file, copy rswift file and place it in the directory where your .xcodeproj file lives, eg. scripts/rswift
  • Open the project.yml file and declare R.swift as a dependency. Make sure to add RswiftLibrary as the package's product.
  • Modify the build Run script with the following changes:

"$SRCROOT/scripts/rswift" generate "$SRCROOT/R.generated.swift"

By following these steps, you can integrate R.swift into Xcodegen using SPM.

0
On

In the end, I just moved to SwiftGen) It turned out to be much easier to work with it in the XcodeGen project.