开发者

When to define your ivars as pointers?

开发者 https://www.devze.com 2023-01-03 08:18 出处:网络
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

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

精彩评论

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