A property/ivar/outlet was just changed, how do I find out who did it?

I see this post all the time on StackOverflow. The answer is surprisingly simple:

– if you have an ivar, convert it to a property with a synthesize ivar=ivar if needbe to avoid having to prepend a “_” to usages

– write your own setter, and add logic tests and NSLog messages

Рput a breakpoint on the NSLog message, and run your app

Voila! You app stops when the value changes, and you can see who the offender is!


Making absolutely sure no one uses the ivar instead of the property

Use synthesis to create a really ugly name that will make it unmistakeable:

    @synthesize myVar=_DO_NOT_ACCESS_myVar;

There is no way in h*ll anyone is going to write:

    _DO_NOT_ACCESS_myVar = @"Hah"; // :-)