views:

17

answers:

1

Does anyone know of a decent way to catch forgetting to use 'self.' when setting variables? Is there an xcode compiler setting that can trigger warnings? I'm trying to think of the easiest way to make ensuring there is a 'self.' in front of assignments foolproof.

+3  A: 

The best I can suggest so far is to differentiate the ivar and property name, like:

@implementation Person
@synthesize firstName = firstName_;
@end

so it is harder to make mistake, though it is not foolproof.

tia
That would certainly help enforcing using 'self.' in all cases of getting and setting, but not entirely what I'm looking for. I wanted to allow things like myCGPoint.x = 5 without requiring self. Maybe it's just better to give in and use this approach to enforce tagging self. on everything though, than deal with the occasional difficult to find bug.
Joey

related questions