Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of "Self" keyword in Objective-C [duplicate]

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.

like image 859
codeluca Avatar asked Dec 04 '22 12:12

codeluca


1 Answers

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.

like image 112
aleroot Avatar answered Dec 27 '22 02:12

aleroot