I believe the switch is actually calling the getter, thus always setting the background to red.
Test case:
var helpme: Int {
get {
return 1
}
set {
switch helpme {
default:
print(helpme)
}
}
}
func testme() {
helpme = 20
print(helpme)
}
output:
1
1
switch self.animate { // calls the getter which returns red
case .changeColor(let newColor, let duration):
UIView.animate(withDuration: duration) {
self.backgroundColor = newColor
}
case .hideView(let duration):
UIView.animate(withDuration: duration) {
self.alpha = 0
self.isHidden = true
}
}
I think a property is too limited for the number of things you want to do.
I would suggest using a function for each of your animations and maybe having a property state animationType: AnimationType? if you want to know the current animation state of your view. Although this would require creating a new UIView class with the animationType property since you can't declare variables in extensions.
class AnimatingView: UIView {
var animationType: AnimationType?
}
enum AnimationType {
case changingColor
case hidingView
}
func changeColor() {
animationType = .changingColor
// change color
}