IVar property, access through self?

I understand that when accessing setter / getter methods for properties, I have to use [ self setThisValue:@"a"];, and not thisValue = @"a";. However, in the example below, I see that adding my own documents that I send a message to the iVar property is more likely than a variable with local scope, but does it do anything else in this case?

@interface CustomController : UIViewController {
    NSMutableArray *foundList;
}
@property(nonatomic, retain) NSMutableArray *foundList;
@end

.

[[self foundList] addObject:eachObject]; // I usually write this ...

OR

[foundList addObject:eachObject];

Gary.

+3
source share
4 answers

If you have a specific property for ivar, you should use it, and not directly access ivar. This allows subclasses to override setter / getter and do something else to simply extract the value from ivar.

The only exception is in the init and dealloc methods.

+4
source

[[self foundArray] addObject:eachObject];

, , , . , - , , , -, . ( )

+2

- , - , , .

+1

self.ivar . , . self.ivar = newObject. self.ivar, , newObject . , , , ivar . . , , self.ivar...

0
source

All Articles