0

I'm subscribing to KVO notifications from an object. I seem to be receiving notifications for keypaths of the object that shouldn't be changing.

Whats the best way to determine how these objects were changed (i.e. by what code) that resulted in notifications being sent.

Ideally there is someway to trace back to the line of code that changes an object that cause the KVO notification. Is this possible?

aloo
  • 5,331
  • 7
  • 55
  • 94
  • 2
    Maybe this could help: http://stackoverflow.com/questions/15648024/any-way-to-see-who-is-triggering-changes-re-key-value-observing – Dave FN Jul 10 '13 at 16:57

2 Answers2

1

So silly of me, you can actually just set a breakpoint in the observer and look at the stack trace.

aloo
  • 5,331
  • 7
  • 55
  • 94
0

Let's say you have the UIButton and you want to know what code changes it frame.

You can make the subclass of the UIButton and override it's setFrame: method. Nextly, just initialize the MyButton class instead of UIButton class.

#import "MyButton.h"

@implementation MyButton

- (void)setFrame:(CGRect)frame
{
  [super setFrame:frame]; // set the breakpoint here
}

@end

Now every time the frame of the UIButton changes you will stop at breakpoint and u will be able to watch the stack trace and investigate what code caused the change of the frame.

Rafał Augustyniak
  • 2,011
  • 19
  • 14