Skip to content

Commit

Permalink
Add safety check for cgColor.components
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoffer Winterkvist committed Oct 5, 2016
1 parent f4c7cee commit b8682f9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Source/iOS/UIColor+Hue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public extension UIColor {
}

internal func rgbComponents() -> [CGFloat] {
guard let RGB = cgColor.components else {
guard let RGB = cgColor.components, RGB.count == 3 else {
return [0,0,0]
}
return RGB
}

public var isDark: Bool {
let RGB = rgbComponents()
return (0.2126 * RGB[0] + 0.7152 * RGB[1] + 0.0722 * RGB[2]) < 0.5
Expand Down Expand Up @@ -126,7 +126,7 @@ public extension Array where Element : UIColor {
gradient.colors = self.map { $0.cgColor }

if let transform = transform {
gradient = transform(&gradient)
gradient = transform(&gradient)
}

return gradient
Expand Down

0 comments on commit b8682f9

Please sign in to comment.