views:

72

answers:

3

I hope i did not skip this part in the ObjC manual but is it possible to refer to a class from within one of its class methods? Like in PHP you would use "this" to refer to the current instance, while "self" refers to the instance's class the ObjC equivalent of "this" would be "self", so what would be the ObjC equivalent of PHP's "self", if there is one?

+2  A: 

If self is an instance of an object, you can get the object's class with [self class].

amrox
-1 he's asking about class methods, not instance methods.
Dave DeLong
+5  A: 

Inside a class method, self refers to the current class (the class's Class object). Inside an instance method, self refers to the current instance of that class.

mipadi
+1 this is the correct answer.
Dave DeLong
Thank you very much, this was exactly the information I needed (and obviously missed in the runtime reference).
karsten
A: 

Every Objective-C method gets two parameters implicitly: self, and _cmd. Inside any method, self is the receiver of the message that invoked the method, unless you assign a different value to it. In a class method, the receiver is a class. In an instance method, the receiver is an instance.

NSResponder