To create an instance, you need to send a message directly to a class. This invokes a "class method", which is different from an instance method in that it may be sent only to a class.
To make it possible to send such a message, the Objective-C compiler creates a special "class object".
You send alloc followed by init (for reasons that will not be covered here.)
MKNote *aNote; aNote = [MKNote alloc]; [aNote init]; |
An object-valued variable (such as "aNote" above) need not have a type. To define an untyped object-valued variable, use the special type id. Example: id aNote;
self, when used in a method definition, refers to the object that's receiving the message.
Sometimes "class-wide" behavior is implemented by class methods. For example:
[MKConductor startPerformance]. |