http://www.techrepublic.com/blog/software-engineer/what-you-need-to-know-about-automatic-property-synthesis/
1 2 3 4 |
@interface Sign : NSObject { } @property(nonatomic, retain) NSString * playerName; |
.m
1 2 3 4 |
@syntehsize playerName @implementation @end |
- By prefixing playerName with self. you will access the property
- without it you will directly reference the instance variable
Hence self.playerName = @”hehe”, will make you access the either automatically generated set or custom set method.
whereas playerName = @”hehe”, will literally have you use the instance variable.
No Synthesize
1 2 3 4 |
@interface Sign : NSObject { } @property(nonatomic, assign) double probability; |
Without @synthesize probability in the .m file,
_probability is the iVar
self.probability means to access the automatically generated get/set methods
try it
1 2 3 4 5 6 7 8 9 10 |
-(id)initWithName:(NSString*)newName andNSDate:(NSDate*)date andProbability:(double)prob { if(self = [super init]) { _probability = 0.01f; //ok probability = 3.0f; //error self.probability = 10.0f; //ok } return self; } |