All Objective-C methods get an implicit parameter called self
that is a stack variable of type id
that points to the current instance. In fact, any C function can be used as an Objective-C method if its first two parameters are type id
and SEL
(see below).
self
is not a reserved keyword in Objective-C like this
in Java. You can, for example reassign self
within the method. This is a standard pattern in init
methods:
-(id)init {
if( (self = [super init]) ) {
// do initialization here
}
return self;
}
but reassigning self
is rarely used in any other context.
You can use self
like any other variable of type id
: [self bar:i]
in the example you provide.
For completeness, all Objective-C methods also get an implicity parameter named _cmd
as well which is the selector (type SEL
) of the method being called. See the Objetive-C Runtime Reference for more info.