views:

158

answers:

3

I have an app that appears to run without problems in normal use. The Clang Static Analyzer reports no problems either. When I try to run it in Instruments, it fails with an unrecognized selector exception.

The offending line is a simple property setter of the form:

self.bar = baz;

To figure out what's going on, I added an NSLog() call immediately above it:

NSLog(@"class = %@ responds = %d", [self class], [self respondsToSelector:@selector(setBar:)]);
self.bar = baz;

On the emulator (without Instruments) and on a device, this shows exactly what I'd expect:

class = Foo responds = 1

When running under Instruments, I get:

class = Foo responds = 0

I'm stumped as to what could cause this. Perhaps a different memory location is getting tromped on when it's in the Instruments environment? Can anyone suggest how I might debug this?

A: 

If bar belongs to self, can't you do bar=baz; ?

mcandre
That won't notify any observers of the property, and it's possible that bar isn't even directly implemented as an instance variable. It may be synthesized from other values. For example, a "fullname" property could be stored in the "firstname" and "lastname" ivars and not have any ivar directly backing it up.
BJ Homer
A: 

Check your properties. Perhaps to you need a cast on baz?

JoePasq
A: 

There's not enough information here to know what's going on, but then, if you knew what information to provide you'd probably have already fixed it. So. A few things to check:

  • Is the "self" pointer being swizzled in any way? Try printing out the value of self at various points just for sanity's sake
  • When your code runs in Instruments, is it running in a different mode? (32-bit vs. 64-bit, Garbage collected vs. Retain-Release, etc.) I'm not sure why any of those would have an effect, but if it's running in a different mode, that's something to look into.
  • Are you synthesizing the setter correctly? Or is it being provided dynamically (via Core Data, etc.)? If you manually specify a setBar: method, do you still get the error?
BJ Homer