Swiftgen: Invalid redeclaration of 'Color'

Created on 21 Aug 2017  路  5Comments  路  Source: SwiftGen/SwiftGen

I'm using swiftgen in an Xcode 8/Swift 3 project for colors, assets and strings, and since upgrading to v5, I'm getting "Invalid redeclaration of 'Color'" errors, since both the generated Colors.swift and Assets.swift file contain the line typealias Color = UIColor.

bufix

All 5 comments

Thanks for the bug report @gereons

Sadly we can't make the typealias private to avoid it leaking between the two files, and if we want to keep the templates compatible with both iOS and macOS we still need that typealias. So the only solution I see is we're gonna rename the typealias in the assets templates to avoid name collision.

We'll try to do a release with the fix ASAP; in the meantime you could create a custom template by duplicating the bundled template (run swiftgen templates cat xcassets-swift3 >custom-xcassets.stencil), amend it and use it instead of the bundled one.

Yes, that's what I'm doing right now.
Alternatively, if I could control which of the two files actually has the alias/extensions, that would work too, something like --suppress-color-alias which I can add to one of the invocations.

Yeah, we also thought about renaming both the typealiases in each files, to name them ColorsColorTypeAlias and AssetsColorTypeAlias or something like that. But some people might already take advantage of that Color typealias declaration in their own code maybe (after all it was accessible from their own code) so would be breaking to rename both.

A --param noColorAlias would work but seems strangely unbalanced if the user have to choose on which one to remove it. But could be a solution indeed

@djbe Maybe we could use a typealias {{param.coloralias|default:"Color"}} = UIColor for the colors template and typealias {{param.coloralias|default:"AssetsColorTypeAlias"}} for the xcassets templates, that way (1) we have sensible defaults, (2) we keep the old Color typealias to avoid breaking code of users who relied on it, (3) but still offers a way to change it in case those default names causes conflicts with their own code (i.e. if they declare a Color type in their own code already before trying to integrate SwiftGen to their project)

@gereons 5.1.1 has been released on GitHub (zip in GitHub Release) and CocoaPods, and is pending on homebrew to be release there too

Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danielsaidi picture danielsaidi  路  7Comments

djbe picture djbe  路  6Comments

drjasonharrison picture drjasonharrison  路  5Comments

marcelofabri picture marcelofabri  路  6Comments

embassem picture embassem  路  3Comments