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.
Asked
Active
Viewed 188 times
0
-
1make `ivar` private and thus the only way to access it is using properties – Inder Kumar Rathore Nov 05 '13 at 09:07
-
But its in same class – Sachin Nov 05 '13 at 09:08
-
1if it's your class then why are you using ivar directly, use property. – Inder Kumar Rathore Nov 05 '13 at 09:25
-
i m using property only and i am doing some task when its value getting change. But soon i will be out of this project and somebody else will come and he might try to give direct value to iVar. Because of that only i was thinking is it possible, – Sachin Nov 05 '13 at 09:45
1 Answers
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