iOS Setters and Getters and Underscored Property Names

后端 未结 2 1926
臣服心动
臣服心动 2020-12-30 11:06

So I have a NSString property named description, defined as follows:

@property (strong, nonatomic) NSMutableString *description;

I\'m able

2条回答
  •  渐次进展
    2020-12-30 12:08

    1) NSObject already has a method named description. Pick another name

    2) Your setter is an infinite loop

    But as to your actual question: The compiler will only autogenerate backing variables if you do not override both methods.

    P.S. No, you can't just "use self.description instead" because then your getter would also be an infinite loop.

提交回复
热议问题