When to use self on class properties?

前端 未结 8 1344
暗喜
暗喜 2020-12-03 09:03

When is self needed for class properties? For example:

self.MyProperty = @\"hi there\";

vs

MyProperty = @\"hi there\";
         


        
8条回答
  •  悲哀的现实
    2020-12-03 09:38

    Still not clear on when to use the accessors and when to do direct assignment on ivars ? I have seen lot of Apple examples which directly access the ivars. So using properties for all ivars seems pedantic overkill.

    It seems only significant ivars which need to be around longer and are accessed outside tend to use the properties.

    Would appreciate some Cocoa gurus to step in and clarify.

提交回复
热议问题