Q:  Does Objective-C have any concept of class variablesÐvariables managed by the class object like those in SmallTalk?

A:  In Objective-C the class object has no variables.  Objective-C provides only internal data structures for the class, none that you can set or access directly.  The class object also has no access to any instance variable; it can't initialize, read, or alter them.

Therefore, for all the instances of a class to share data, an external variable of some sort is required.  Some classes declare static variables and provide class methods to manage them.  Declaring a variable static in the same file as the class definition limits its scope to just the classÐand to just the part of the class that's implemented in the file.  Unlike instance variables, static variables are not visible to subclasses or categories of the class.

Static variables help give the class object more functionality than just that of a ªfactoryº producing instances; it can approach being a complete and versatile object in its own right.  A class object can be used to coordinate the instances it creates, allocate instances from lists of objects already created, or manage other processes essential to the class.  

You can use the +initialize method to set up and initialize class variables and you can provide class methods to set/retrieve the variables.  See also one of the examples in Release 2 (/NextDeveloper/Examples/SortingInAction) which uses this strategy to share one mutex variable across many instances of a class.

QA708

Valid for 1.0, 2.0, 3.0