Objective-C is @synthesize required or optional?

前端 未结 2 756
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 06:10

sorry I\'m a newbie iOS developer, recently I\'ve briefly heard that @synthesize is now @synthesize in a certain version of Xcode and that the compiler will auto synthesize

相关标签:
2条回答
  • 2020-12-14 06:53

    Unless you've been using it like I have, then you still need it, as far as I can tell:

    in .h:

    @property int32_t FwdID;
    

    in .m:

    @synthesize FwdID;
    

    usage inside class:

    FwdID = 0;
    

    From what I can tell, if you want the default to work for you, you'll have to type _FwdID = 0; in the code, which just looks ugly to me.

    So if you are like me (breaking all the standard coding conventions I assume), you'll still need to use synthesize.

    0 讨论(0)
  • 2020-12-14 06:54

    No we don't need to do that as of Xcode 4.4, which added a feature called Default Synthesis Of Properties.

    Simply put, it generates this automatically:

    @synthesize name = _name;
    
    0 讨论(0)
提交回复
热议问题