[Solved] How can I check array count changes in Swift [closed]


Property observers observe and respond to changes in a property’s
value. Property observers are called every time a property’s value is
set, even if the new value is the same as the property’s current
value.

You have the option to define either or both of these observers on a
property:

  • willSet is called just before the value is stored.
  • didSet is called immediately after the new value is stored. source
var arr = [1,2] {
    willSet {
        let newCount = newValue.count
        callMe(count: newCount)
    }
    didSet {
        let newCount = arr.count
        callMe(count: newCount)
    }
}

func callMe(count: Int) {
    print(count)
}

solved How can I check array count changes in Swift [closed]