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

Error running --swift #29

Open
GabrielMassana opened this issue Apr 20, 2016 · 1 comment
Open

Error running --swift #29

GabrielMassana opened this issue Apr 20, 2016 · 1 comment

Comments

@GabrielMassana
Copy link

First of all let me say that this is a great tool.

I created a new Swift project to test the tool:
I also added 2 images to Assets.xcassets

$ cd [project folder]
$ rvm use system
$ sudo gem install xcres
$ xcres install --swift --verbose

Ⓥ Verbose mode is enabled.
⚠ Argument XCODEPROJ is not set. Using the current directory.
✓ Use ./xcres_test_swift.xcodeproj as XCODEPROJ.
Ⓥ Found target group, will use its path as base output path.
⚠ Didn't find support files group
Execute build first:
Ⓥ Verbose mode is enabled.
✓ Use xcres_test_swift.xcodeproj as XCODEPROJ.
Ⓥ Found #0 resource bundles in project.
Ⓥ Found #0 image files in project.
Ⓥ Found #1 asset catalogs in project.
Ⓥ Found asset catalog Assets.xcassets with #4 image files.
Ⓥ Add section for AssetsAssets with 4 elements
Ⓥ Strings files in project: []
Ⓥ Native development languages: ["en"]
Ⓥ Used languages for .strings files: []
Ⓥ Preferred languages: []
Ⓥ Strings files after language selection: []
Ⓥ Non-ignored .strings files: []
⚠ Skip invalid key: '.'. (Was transformed to empty text)
✓ Directory did not exist. Will be created.
✓ Successfully updated: /Users/Gabriel/Desktop/xcres_test_swift/xcres_test_swift/Resources/R.swift
✓ Successfully integrated into xcres_test_swift.xcodeproj

I've got now an R.swift file into the project. Great!

The problem is the content of the file:

// generated by xcres
//
// DO NOT EDIT. This file is machine-generated and constantly overwritten.
// See https://github.com/mrackwitz/xcres for more info.
//

public class R {
    public enum AssetsAssets: String {
        /// AppIcon
        case app = "AppIcon"
        /// earth
        case earth = "earth"
        /// sun
        case sun = "sun"
    }
}

public extension R.Strings {
    public var localizedValue: String {
        return NSLocalizedString(self.rawValue,
                                 bundle: NSBundle(forClass: R.self),
                                 comment: "")
    }
}

Xcode is complaining:
'Strings' is not a member type of 'R'

So this line is wrong:

public extension R.Strings {

changing it to this, stops complaining:

public extension AssetsAssets {

I think then the file needs to import UIKit.

@mrackwitz
Copy link
Member

The problem here is that the code generation of the tool expects at this place that the analyzer will always return a strings section, which would be generated as an additional enumeration R.Strings. The extension makes only really sense for localized strings. Currently you can workaround that by adding localized strings file to your project. The file would need to import at least Foundation. UIKit doesn't seem to be required so far, unless there would be an extension for image assets, which allows to return UIImage instances directly via a computed property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants