Swifterswift: Color extension recommend,

Created on 4 Apr 2019  路  5Comments  路  Source: SwifterSwift/SwifterSwift

In swift, colorLiteral can reflect color, is this more intuitive?

浼佷笟寰俊鎴浘_0f1fe2fa-733a-4980-85f7-ddfafbcaa567

public static let facebook1 = #colorLiteral(red: 0.231372549, green: 0.3490196078, blue: 0.5960784314, alpha: 1)

discussion

Most helpful comment

I think it's more useful to see the component values in source code than a color swatch.

All 5 comments

I think it's a matter of taste. Personally I wouldn't focus on changing it, but happy to hear the thoughts of others.

I think it's more useful to see the component values in source code than a color swatch.

Thank you for your suggestion @fanglinwei, I see how color literals makes the code looks better in Xcode, however, I have to agree with @guykogus and @chulbert here for the following two reasons

  1. Color literals do not look like this in another text editors
  2. Using values is more readable; especially for people wanting to copy and paste the values

Personally, i do this:

extension UIColor {

static let facebook: Color = 0x3B5998

but i have my Color in my personal project setup differently than here in SwifterSwift:

class Color: UIColor, ExpressibleByIntegerLiteral {

    public required convenience init(integerLiteral value: IntegerLiteralType) {
        let red = CGFloat((value & 0xFF0000) >> 16) / 255
        let green = CGFloat((value & 0x00FF00) >> 8) / 255
        let blue = CGFloat(value & 0x0000FF) / 255
        self.init(red: red, green: green, blue: blue, alpha: 1)
    }
}

I'm going to close this issue for now, feel free to open again to extend the discussion :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omaralbeik picture omaralbeik  路  3Comments

omaralbeik picture omaralbeik  路  5Comments

marcocapano picture marcocapano  路  5Comments

SD10 picture SD10  路  3Comments

pawurb picture pawurb  路  3Comments