diff --git a/Source/iOS/UIColor+Hue.swift b/Source/iOS/UIColor+Hue.swift index 6430276..1bab3a7 100644 --- a/Source/iOS/UIColor+Hue.swift +++ b/Source/iOS/UIColor+Hue.swift @@ -21,10 +21,15 @@ public extension UIColor { } } + guard let intCode = Int(hex, radix: 16) else { + self.init(white: 1.0, alpha: 0.0) + return + } + self.init( - red: CGFloat((Int(hex, radix: 16)! >> 16) & 0xFF) / 255.0, - green: CGFloat((Int(hex, radix: 16)! >> 8) & 0xFF) / 255.0, - blue: CGFloat((Int(hex, radix: 16)!) & 0xFF) / 255.0, alpha: 1.0) + red: CGFloat((intCode >> 16) & 0xFF) / 255.0, + green: CGFloat((intCode >> 8) & 0xFF) / 255.0, + blue: CGFloat((intCode) & 0xFF) / 255.0, alpha: 1.0) } /// Adjust color based on saturation