Created
May 6, 2015 02:56
-
-
Save tristaaan/78a788775611f834ca86 to your computer and use it in GitHub Desktop.
UIColor ==, !=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func == (left:UIColor, right:UIColor) -> Bool{ | |
let lref:CGColorRef = left.CGColor | |
let rref:CGColorRef = right.CGColor | |
let lComponents = CGColorGetComponents(lref) | |
let rComponents = CGColorGetComponents(rref) | |
if CGColorGetNumberOfComponents(lref) == CGColorGetNumberOfComponents(rref) { | |
return floor(lComponents[0]*255) == floor(rComponents[0]*255) && | |
floor(lComponents[1]*255) == floor(rComponents[1]*255) && | |
floor(lComponents[2]*255) == floor(rComponents[2]*255) && | |
floor(lComponents[3]*255) == floor(rComponents[3]*255) | |
} | |
else { | |
return false | |
} | |
} | |
func != (left:UIColor, right:UIColor) -> Bool { | |
return !(left == right) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment