Skip to content

Commit

Permalink
Merge pull request #58 from jiangpengyun/master
Browse files Browse the repository at this point in the history
add guard block to prevent possible crash
  • Loading branch information
zenangst authored Jan 15, 2019
2 parents eb64f52 + 4a0c8ad commit c8e02ce
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Source/iOS/UIColor+Hue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8e02ce

Please sign in to comment.