Custom Getter & Setter iOS 5

后端 未结 3 1690
挽巷
挽巷 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条回答
  •  伪装坚强ぢ
    2020-12-13 04:59

    The thing you’re missing is that the Objective-C compiler basically turns the self.foo = bar syntax into [self setFoo:bar], and self.foo into [self foo]. Your methods, as currently implemented, are calling themselves. As Jeremy suggests, you need to implement them such that the setter actually assigns the value it’s called with to an instance variable on your class and the getter returns the value of that instance variable.

提交回复
热议问题