QBsmartguy
QBsmartguy

Reputation: 85

Checking if a variable has changed and than update shape Swift Xcode

Is there a way for swift code to check if this variable changes and than change the shape of an object?

var Shape = 0.4
let a = (self.size.width + self.size.height) * Shape

Upvotes: 0

Views: 710

Answers (1)

Nilupul Sandeepa
Nilupul Sandeepa

Reputation: 768

Using property observers you can achieve what you are looking for. didSet will be called after varibale value changed.

var variable1 = 0 {
    didSet {
        onValueChange()
    }
}
    
func onValueChange() {
    print("Change \(variable1)")
}

Upvotes: 2

Related Questions