Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About the keyword of `self`

Tags:

objective-c

+ (void)Foo;
- (void)Foo;

In the method, - (void)Foo, the keyword self means an instance of the class. But in the method, + (void)Foo, What does the keyword self mean? Does it mean the Class ?

like image 695
AechoLiu Avatar asked May 27 '11 00:05

AechoLiu


1 Answers

self is one of the two implicit parameters to every method. It is a pointer to an object, and initially it is whatever object received the message to invoke the method that's executing. When the method in question is an instance method, self will be an instance of the class in which the method is defined, or one of its subclasses. In the case of a class method, self will be the class object.

like image 92
NSResponder Avatar answered Nov 15 '22 11:11

NSResponder