1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#import "MyClass.h" @implementation MyClass //_word is instance variable (ivar) //word is used in self.word fashion for get/set @synthesize word = _word; //you can declare your own custom get/set method like so, which we call an "explicit definition" //here is where we have our custom lazy load of ivar _word - (NSString *)word { if (_word == nil) { _word = [NSString stringWithFormat:@"some word"]; } return _word; } -(instancetype)init { if(self=[super init]) { //WRONG, compiler will throw error [word stringByAppendingString:@"aya"]; //access instance variable through synthesized or your own custom get/set methods [self.word stringByAppendingString:@"6680"]; //access instance variable itself [_word stringByAppendingString:@""]; } return self; } @end |