The Swift documentation says that adding initializers in an extension is possible, and the example in the document is about adding an initializer to a struct. Xcode doe
Changing the parameter types will also work.
extension UIColor {
convenience init(red: Int, green: Int, blue: Int, alpha: CGFloat) {
let normalizedRed = CGFloat(red) / 255
let normalizedGreen = CGFloat(green) / 255
let normalizedBlue = CGFloat(blue) / 255
self.init(red: normalizedRed, green: normalizedGreen, blue: normalizedBlue, alpha: alpha)
}
}
Usage:
let newColor: UIColor = UIColor.init(red: 74, green: 74, blue: 74, alpha: 1)
I would usually forget the redundant work of dividing the component values by 255. So I made this method to facilitate me.