Swift UIColor initializer – compiler error only when targeting iPhone5s

It probably has to do with a mismatch between Float and Double. Basically, if the arguments are expected to be CGFloats, you need to pass CGFloats.

let color = UIColor(red: CGFloat(red), green: CGFloat(green), blue: CGFloat(blue), alpha: CGFloat(alpha))

What’s important to understand here is that CGFloat is defined as Float on 32 bit platforms, and Double on 64 bit platforms. So, if you’re explicitly using Floats, Swift won’t have a problem with this on 32 Bit platforms, but will produce an error on 64 bit.

Leave a Comment