Search code examples
objective-cdebuggingbreakpointsconditional-breakpoint

Is it possible to use a symbolic breakpoint (or similar) with a dynamic property setter?


At some point in the app, a property in my object is getting set to a strange value. Normally, I would debug something like this by setting a symbolic breakpoint similar to this:

enter image description here

This way, when someone tries to set the property to the value I'm looking for, I get a hit and I can look at the trace to see where it's coming from.

Unfortunately, this doesn't work when you're dealing with properties declared as @dynamic. Is there another way to do something similar?

More Info

The object in question is an NSManagedObject

This project uses RestKit and its very possible that this is where the value is coming from.


Solution

  • You can implement the setter yourself and put a breakpoint in there. Implementing a core data property setter is a bit different than normal. Something like this should work:

    - (void)setFoo:(NSObject *)foo {
        [self willChangeValueForKey:@"foo"];
        [self setPrimitiveValue:foo forKey:@"foo"];
        [self didChangeValueForKey:@"foo"];
    }