I tried converting the following Objective -C code block to Swift using Swiftify.
#define HEXCOLOR(hex) [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16)) / 255.0 green:((float)((hex & 0xFF00) >> 8)) / 255.0 blue:((float)(hex & 0xFF)) / 255.0 alpha:1]
This code is called as:
_contentView.backgroundColor = HEXCOLOR(0x24B491);
Here is the converted code output
func HEXCOLOR(_ hex: Any) -> UIColor {
UIColor(red: CGFloat((Float((hex & 0xff0000) >> 16)) / 255.0), green: CGFloat((Float((hex & 0xff00) >> 8)) / 255.0), blue: CGFloat((Float(hex & 0xff)) / 255.0), alpha: 1)
}
The code conversion seems correct in all parts except for the type of the function's input parameter.
P.S. There are many GitHub gists which convert hexString to UIColor.