views:

39

answers:

1

I've been sort of on the fence on this one for a while, but I'd like to know what people think about accessing instance variables directly from within an Objective-C class implementation?

Using accessors and mutators makes a lot of things easy, but for simple things, is it bad to access the instance variable directly? Is the best practice different for private instance variables?

+2  A: 

If you always use your accessor methods, then you can be assured of memory management being handled properly, especially if those methods are synthesized. That being said, if we're talking about accessing ivars of primitive types, it doesn't hurt anything to use them directly within the implementation of your instance methods.

NSResponder