-
Notifications
You must be signed in to change notification settings - Fork 6
Some thoughts about class variables
Nat! edited this page Nov 22, 2018
·
3 revisions
Use a sharedInstance and store the information in the instance.
You can tack a variable number of bytes to each class using +extraClassSize
. You can then use MulleObjCGetClassExtra to get a pointer to that area.
Pros: very efficient Cons: subclasses do not inherit the extraClassSize method. No way to call [super extraClassSize]. It is in no way clear that MulleObjCGetClassExtra( [X class]) and MulleObjCGetClassExtra( [x class]) might yield different values, if x is subclass of X.
It's unclear how this is in anyway superior to using a static struct and store the class information there.
Cons: Uses a concurrent hashmap. Who manages the keys ? Never used in in real life.