Here is a nice way of using Swift features (extensions, computed properties and tuples) to do the same thing in just a few lines of code.
extension UIColor {
var hsba: (h: CGFloat, s: CGFloat, b: CGFloat, a: CGFloat) {
var hsba: (h: CGFloat, s: CGFloat, b: CGFloat, a: CGFloat) = (0, 0, 0, 0)
self.getHue(&(hsba.h), saturation: &(hsba.s), brightness: &(hsba.b), alpha: &(hsba.a))
return hsba
}
}
Swift 3.2 / 4 minor update
Swift 3.2 / 4 enforced a new warning triggered with the previous code because you were modifying the hsba
variable several times within the same call to getHue
Simultaneous accesses to parameter 'hsba', but modification requires exclusive access; consider copying to a local variable.
extension UIColor {
var hsba: (h: CGFloat, s: CGFloat, b: CGFloat, a: CGFloat) {
var h: CGFloat = 0, s: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0
self.getHue(&h, saturation: &s, brightness: &b, alpha: &a)
return (h: h, s: s, b: b, a: a)
}
}