Encapsulating data in Objective-C means that only the class itself needs to relate to instance variables. Therefore, you should always mark them as private and only expose them through properties, since this:
@interface Foo : NSObject { @private int numberOfBars; Baz* contentBaz; } @property(nonatamic, assign) int numberOfBars; @property(nonatomic, retain) Baz* contentBaz; @end
This means that the class can implement validation in setter methods. And it's even better if you use @synthesize to generate your getters and seters, than you don't need to worry about Cocoa's memory model at all (except for freeing your ivars in dealloc).
Peylow
source share