September 2002
Intermediate to advanced
1272 pages
31h 12m
English
Accessors are methods used to query or change the internal state of an object. The internal state of objects is usually stored in instance variables. There is commonly a one-to-one correspondence between instance variables and accessor methods. The convention of using accessors is an extremely good practice that is ubiquitous in the Cocoa frameworks, but is optional.
The following simple class declaration shows how accessors are used.
@interface MYClass : NSObject
{
NSRect _myRect;
}
- (void)setRect:(NSRect)aRect;
- (NSRect)rect;
- (void)getRect:(NSRect *)aRectPtr;
@end NSRect is a C structure defined in NSGeometry.h. The -setRect: method passed the aRect argument by value even though NSRect is a structure. Similarly, the -rect
Read now
Unlock full access