Jonathan Sterling Jonathan Sterling - 11 months ago 76
Objective-C Question

What does class_getClassVariable() do?

If instance variables belong to an instance of a class, class variables would belong to an instance of a metaclass, I should think. But my experience with the Objective-C metaclass tells me that this is unlikely.

I'm wondering what

does as opposed to
, and why there is not a
in the runtime.


I found a discussion about it here:

Nope, it's not possible. There is no compiler support, and there is no runtime support; class_getClassVariable(cls, name) merely calls class_getInstanceVariable(cls->isa, name).

If it were possible, it likely would not give you a new variable on each subclass anyway. Objective-C's metaclasses are not quite first- class enough for that to work well.