In a project I'm creating, I have various classes. One of my classes has an instance of NSMutableArray that holds objects of another one of my classes. I thought I had a firm understanding on this topic, but somehow it got jumbled up in my mind again.
When initializing an instance of this class, I have this initilize method:
- (MMShowMovement *) initWithMovementName: (NSString *) name andNumber: (NSInteger) number {
if( [super init] ) {
[self setMovementTitle: name];
[self setMovementNumber: number];
[self setDotArray: [[NSMutableArray alloc] init]];
}
return self;
}
Later on, after an instance of this class is created, I can add objects to the NSMutableArray "dotArray." Here is that method.
- (void) addDot: (MMDot *) dot {
[dotArray addObject: dot];
}
(I know, its simple) I'm wondering, when I use "dotArray" in this method, I am accessing the dotArray object for the instance of the class for which this method has been invoked, correct? Or should I use the self keyword here also?
- (void) addDot: (MMDot *) dot {
[[self dotArray] addObject: dot];
}
Honestly, I'm not really sure. I believe it is the former, but I'm unsure as to why. And it is not necessary to use the self keyword in this method, why do I have to use it in the initializer to access the object?