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

2019-03-14 08:38发布

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条回答
Viruses.
2楼-- · 2019-03-14 09:33

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.

查看更多
登录 后发表回答