Custom Getter & Setter iOS 5

后端 未结 3 1697
挽巷
挽巷 2020-12-13 04:36

I want to override the getter and setter in my ObjC class using ARC.

.h File

@property (retain, nonatomic) Season *season;

.m File

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 05:05

    If you are going to implement your own getter and setter, you'll need to maintain an internal variable:

    @synthesize season = _season;
    
    - (void)setSeason:(Season *)s {
        // set _season
        //Note, if you want to retain (as opposed to assign or copy), it should look someting like this
        //[_season release];
        //_season = [s retain];
    }
    
    - (Season *)season {
        // return _season
    }
    

提交回复
热议问题