Should @synthesize be used still?

前端 未结 4 481
一生所求
一生所求 2021-01-19 02:20

I\'m just wondering if @synthesize should still be used even though Xcode does it automatically for properties, simply because it\'s been done that way for so long? Or does

4条回答
  •  不要未来只要你来
    2021-01-19 02:51

    There really is no overall correct answer for this. Other than the specified technical reasons given by the other answers (such as tying an alternate ivar name to a property), I feel it is most important to keep consistent with your code. If you are contributing with older libraries that use @synthesize all over the place, you might want to stick with it in the name of consistency. Otherwise, if you are starting anew and shooting for the less verbose approach, stick with omitting @synthesize as much as possible. I personally like less verbose code, but I value code consistency somewhat more, especially when weeding through thousands of lines of code.

提交回复
热议问题