0

I wanted to get notification when iVar's value changes. Suppose we are changing the vale of a string without calling setter then how i will get to know in same class. Because KVO and overriding setter works with calling setter only. Not with iVar.

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
Sachin
  • 333
  • 1
  • 4
  • 19

1 Answers1

1

There is no way to be notified automatically when you directly alter the value of an ivar. If you want to be notified when the value change, then make it impossible to change the value directly outside of the class by making the ivar private, and inside of the class, force yourself to never change it directly, except in a setter or with a KVC call (setValue:forKey:).

Guillaume
  • 4,331
  • 2
  • 28
  • 31