See class method, instance method.

Objective C's implementation of Classes works such that the classes, themselves, can be treated as objects-- every class has a corresponding "class object" of type NSClass *.

When you call class methods ([classname method]), the class object is where the messages you send to the class name are going. The class name is not, however, the name of the class object-- to get the class object, say either [classname class] or [instanceofclass class] (they're the same). Once you have obtained the class object in this manner, you can do crazy things like pass a class to a function-- like, the following is legal--

- returnArbitraryObjectOfClass: (NSClass *)aClass
    id temp= [[aClass] alloc] init];
    return temp;
Class objects contain, along with some other things, a pointer to the superclass, and unallocated "prototypes" of their member variables (which, since they are unallocated, cannot be used in any way by class methods). Notice: Objective C has no class variables. I.e. there are no "static" variables shared across an entire class. This is generally seen as being a limitation. The comp.lang.objectivec faq suggests that you declare a single extra class instance in the .h file where you at the time you define your class, and use that instance as storage space for anything all class members will need to share.

Log in or register to write something here or to contact authors.