I'm looking through the source code for the CocoaHTTPServer project, more specifically the HTTPServer.m
file and I just don't understand this line:
connectionClass = [HTTPConnection self];
What does this do (is it documented anywhere)? How does it even compile? Should it not be
connectionClass = [HTTPConnection class];
[className self];
is same as[className class];
Returns the class object.
For example:
[Classname self]
is equal to[Classname class]
and returns a reference to theclass
object.A little sample code illustrates this:
}
Output:
In a very basic nutshell
self
is a reference to the current object, you pass that as a variable to (in this case) HTTPConnection, then assign the result of that method to the variable.So if you look at HTTPConnection you'll be able to see how it uses that object reference and what it's going to return.
In this context,
- (id)self
is a method defined onNSObject
. It returns the receiver. For aClass
it should obviously do the same as a call to the-(Class)class
.