开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜