Use of “Self” keyword in Objective-C [duplicate]

社会主义新天地 提交于 2019-12-31 10:53:18

问题


Possible Duplicate:
Objective-C - When to use ‘self’

I can't understand very well the importance and the usage of the "self" keyword in objective-c. It's my first OOP language so i got stuck on some concepts. When i should use "self"? Why is it useful?

Thanks for the answers!

Edit: I can't understand why is this a duplicated post of Objective-C - When to use 'self' when there there is not the explanation of "Self" that i wanted.


回答1:


self is a special variable in Objective-C, inside an instance method this variable refers to the receiver(object) of the message that invoked the method, while in a class method self will indicate which class is calling.

self refers to the actual object that is executing the current method, it is an invisible argument passed automatically by the runtime environment to your instance methods.



来源:https://stackoverflow.com/questions/14535527/use-of-self-keyword-in-objective-c

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