-1

This is a very elementary question but somehow I am not getting it. I have a button in a view which when tapped increases the value of an integer in it by one. I want to know if the value of the variable is changed or not. I know the same could be easily achieved by using Boolean value instead of a Integer but I my specific case use of integer is necessary. I just want to know if the value of a variable is changed or not.

AtharvSalokhe
  • 463
  • 1
  • 4
  • 13

1 Answers1

1

Do you mean something like this?

var counter = 0 {
  didSet {
    if oldValue != counter {
      print("counter was changed from \(oldValue) to \(counter)")
    }
  }
}

Output would look like this:

counter was changed from 0 to 1
counter was changed from 1 to 2
counter was changed from 2 to 3
2h4u
  • 504
  • 3
  • 8