I'm trying to change a UIView's backgroundColor based on its current color. E.g. say MyView is now red, on touch I want to make it blue and vice versa. But I noticed I cannot get the correct name of the UIColor to check the current color.
As an example, if I do:
if MyView.backgroundColor == .systemRed {
print("Red")
} else {
print("Not red")
}
This will always print "Not red", even if I explicitly set MyView.backgroundColor = .systemRed
When I check the color being used:
print("Color = \(MyView.backgroundColor)")
It prints: [...] name = systemRedColor
But when I change .systemRed to .systemRedColor, it gives the error
'systemRedColor' has been renamed to 'systemRed'
and I'm back at where I started.
Can anyone tell me what I am missing? How do I correctly read and set the backgroundColor of UIView?