0

Does the following code call an accessor "set" function or does it modify the pointer myMember directly?

aClass.h

@interface MyClass : NSObject {
    NSArray *myMember;
}

@property (nonatomic, retain) NSArray *myMember;

aClass.c

@implementation GameplayScene

@synthesize myMember;

- (id) init {
    if ( (self = [super init]) )
    {
        myMember = [NSArray array];
    }
}

In other words, I would like to know if the method setMyMember is being called, or if the pointer of myMember is being modified directly.

Likewise, is myMember = [NSArray array] identical to self.myMember = [NSArray array]?

codeperson
  • 8,050
  • 5
  • 32
  • 51
  • 1
    Possible duplicate of [Difference between self.ivar and ivar?](http://stackoverflow.com/questions/4142177/difference-between-self-ivar-and-ivar) and a [whole lot more](http://stackoverflow.com/search?q=%5Bobjc%5D+property+ivar). – jscs May 22 '11 at 00:33
  • Thanks @Josh Caswell. I did look around, but I guess not far enough. – codeperson May 22 '11 at 02:20

1 Answers1

5

Without the self. notation, the instance variable is modified directly. With it, the property setter is called (and since you made it a retain property, the new pointer that it's being set to will be sent a retain message).

See Apple's documentation on declaring and accessing properties.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356