mac-cain13 / R.swift

Strong typed, autocompleted resources like images, fonts and segues in Swift projects
MIT License
9.5k stars 764 forks source link

R.swift doesn't work with Folders in Xcode 16 #914

Closed tomlokhorst closed 1 week ago

tomlokhorst commented 1 month ago

Xcode 16 default project structure uses Folders instead of Groups. R.swift ignores Folders, which means resources in them aren't added to R.*.

As a workaround, you can convert Folders back into Groups, this makes it work with R.swift.

CleanShot 2024-09-26 at 22 19 18@2x

Long term, R.swift should add support for scanning Folders.

nicolasvergoz commented 3 weeks ago

I just finished converting a huge project to folders, only to find out that RSwift is not compatible as is 😫

You have to set --input-type input-files --intput-files <path-to-file-1> --intput-files <path-to-file-2> for each files you need to be processed.

Here is what I did :

"$SRCROOT/scripts/rswift" generate \
  --input-type input-files \
  --input-files $SRCROOT/Resources/Assets.xcassets \
  $(find $SRCROOT/Resources/Fonts -name '*.ttf' -exec echo --input-files {} \;) \
  $(find $SRCROOT/Resources/Fonts -name '*.otf' -exec echo --input-files {} \;) \
  $(find $SRCROOT/Resources/Strings -name '*.strings' -exec echo --input-files {} \;) \
  $(find $SRCROOT/Resources/Strings -name '*.stringsdict' -exec echo --input-files {} \;) \
  $(find $SRCROOT/Resources/Files -name '*.json' -exec echo --input-files {} \;) \
  $(find $SRCROOT/ -name '*.storyboard' -exec echo --input-files {} \;) \
  $(find $SRCROOT/ -name '*.xib' -exec echo --input-files {} \;) \
  --target YOUR_TARGET \
  "$SRCROOT/R.generated.swift"

I don't know if target is necessary though

tomlokhorst commented 3 weeks ago

Indeed --input-type input-files is the version used for SPM plugins. That works by providing individual files, like you did here with the find commands.

The default mode for Xcode build tool plug-ins is --input-type xcodeproj, which scans the Xcode project file for resources. That version doesn't handle folder references yet.

Your solution is a good workaround in the meantime. The target isn't needed.

anatoliykant commented 2 weeks ago

As far as I understand, this problem was fixed in the latest version of swiftlint?! At least this error disappeared for me.

fthdgn commented 2 weeks ago

I opened an PR about this error. https://github.com/mac-cain13/R.swift/pull/920

Also I needed to update XcodeEdit project. https://github.com/tomlokhorst/XcodeEdit/pull/48