tags:

views:

62

answers:

3

Is Class an object, or is it a struct?

+1  A: 

Class types are reference-types and struct types are value types. Instances of class or struct types are called objects.

this. __curious_geek
+3  A: 

Officially, it's implemented as a struct, but the Objective-C runtime let's you treat a Class as an object. Cocoa with Love has a great article on how classes and meta-classes work in Objective-C.

dgrijalva
+4  A: 

Objective-C classes are considered as objects, with a few restrictions (see Objective-C Programming Language):

Class objects are thus full-fledged objects that can be dynamically typed, receive messages, and inherit methods from other classes. They’re special only in that they’re created by the compiler, lack data structures (instance variables) of their own other than those built from the class definition, and are the agents for producing instances at runtime.

Behind the scene, a class definition contains various kinds of information, much of it about instances of the class:

  • The name of the class and its superclass
  • A template describing a set of instance variables
  • The declarations of method names and their return and argument types
  • The method implementations
Laurent Etiemble