When to define your ivars as pointers?
Can someone explain to me when it is necessary to define your ivars as pointers?
I've seen many code samples开发者_运维技巧 that don't use pointers, while others do.
The ivars definition depends on the type of the instance variables.
As a rule of thumb (for general purposes):
- For primitive types (BOOL, short, int or long) or structures (NSRange, CGRect, etc), you should directly use their values (no pointer). Assignment is done by value-copy.
- For class instances, you should use a pointer to reference them.
@interface ClassName : NSObject
{
// instance variable declarations
float width;
float height;
BOOL filled;
CGRect rect;
NSColor *fillColor;
NSView *view;
}
// method declarations
@end
精彩评论