Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generates invalid code when you have 0 resources #827

Open
SpacyRicochet opened this issue May 22, 2023 · 4 comments
Open

Generates invalid code when you have 0 resources #827

SpacyRicochet opened this issue May 22, 2023 · 4 comments

Comments

@SpacyRicochet
Copy link

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
Copy link
Author

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
Copy link

nharbo commented Sep 22, 2023

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
Copy link
Owner

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
Copy link
Collaborator

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)

@tomlokhorst tomlokhorst reopened this Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants