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

Generates invalid code when you have 0 resources #827

Open SpacyRicochet opened 1 year ago

SpacyRicochet commented 1 year ago

It looks like r.swift generates invalid code if you have 0 resources for it to parse. That will currently result in the following R.swift.generated file;

//
// This is a generated file, do not edit!
// Generated by R.swift, see https://github.com/mac-cain13/R.swift
//

import Foundation
import RswiftResources

public let R = _R(bundle: Bundle.module)

public struct _R {
  public let bundle: Foundation.Bundle
  public init(bundle: Foundation.Bundle) {
    self.bundle = bundle
  }
  public func validate() throws {

  }
}

which causes the following build error;

Type 'Bundle' has no member 'module'

Adding a single Localizable.strings resource (for example) immediately solves the issue.

SpacyRicochet commented 1 year ago

Now that I think about it, this is probably caused by the fact that SPM doesn't generate the Bundle.module getter automatically if you do not include resources.

nharbo commented 1 year ago

So, did you fix this? I have tried adding resources: [.process("Resources")], in the target where I set the dependency and plugin, but with no luck

mac-cain13 commented 1 month ago

Just created an empty project with R.swift and I think this now "just works". I don't get any errors with R.swift 7.5.0.

Let me know if I'm overlooking something.

tomlokhorst commented 1 month ago

This issue occurs when integrating Rswift in an SPM package, not in an Xcode project.

When targeting SPM packages, Rswift uses Bundle.module (generated by SPM) When targeting Xcode projects, Rswift uses Bundle(for: BundleFinder.self) (generated by Rswift itself)