Underscore before property name, in setter [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-13 09:23:30

问题


I wrote a setter method -

- (void)setMyProp:(MyProp *)myProp{
    _myProp = myProp;
}

How is underscore put before property name is working? I know this question has been asked, but they are about user setting property name to _myProp, some convention. I am not synthesizing or changing the property name. How this underscore is working?


回答1:


If you are using latest version of LLVM, then the compiler creates @synthesize for you with the syntax:

@synthesize myProp=_myProp;

Therefore you are able to use _myprop even though you have not synthesized explicitly.

*SideNote: _myProp makes you access the property directly, while self.myProp will call accessor. Always use self.myProp



来源:https://stackoverflow.com/questions/15255226/underscore-before-property-name-in-setter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!