fernandodelrio / SwiftColorGen

A tool that generate code for Swift projects, designed to improve the maintainability of UIColors
MIT License
150 stars 5 forks source link

Invalid color functions generated #1

Closed schayes04 closed 6 years ago

schayes04 commented 6 years ago

Two of the colors that got generated for my project were invalid/didn't compile:

/// Color #FF0000 (alpha 217)
class func genFF0000 (alpha 217)() -> UIColor {
    return UIColor(named: "FF0000 (alpha 217)") ?? UIColor.white
}

/// Color #E00000 (alpha 217)
class func genE00000 (alpha 217)() -> UIColor {
    return UIColor(named: "E00000 (alpha 217)") ?? UIColor.white
}

Let me know what else would be helpful to debug

fernandodelrio commented 6 years ago

Thanks for raising that up, the generated name should probably be:

genFF0000_alpha_217

The color names are generated by proximity, so if there's two colors close to the same name, for instance:

hex 000000 -> Black hex 000001 -> Black

Instead of the name of the color, the hex is used to avoid name collision. Also, if the alpha is less than 255, it's appended to the color name to avoid name collision.

Though, the correct should be:

FF0000 (alpha 217) on the Asset Catalog and genFF0000_alpha_217 on the generated file

Probably some wrong string replace : P I will take a look, thanks again by reporting the first issue here 👍