Skip to content

Instantly share code, notes, and snippets.

@tristaaan
Created May 6, 2015 02:56
Show Gist options
  • Save tristaaan/78a788775611f834ca86 to your computer and use it in GitHub Desktop.
Save tristaaan/78a788775611f834ca86 to your computer and use it in GitHub Desktop.
UIColor ==, !=
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