In Objective-C, when are the class pairs - metaclass object and class object, created? Is it in the beginning of the app execution or at the point when you first instantiate the first object of a class?
Asked
Active
Viewed 105 times
1 Answers
7
At the point that the class is added to the class hierarchy. This is generally when the app is launched, but could be later if the class is added by a dynamically loaded library or is created programatically.
The class object and metaclass have to exist at the time that +load
is called (which is the above).

Rob Napier
- 286,113
- 34
- 456
- 610
-
Thanks Rob. So it's before main is called? – Boon Dec 02 '13 at 20:52
-
For statically linked classes, yes. It'll also be before C++ initializers in your framework are called. See the docs for +[NSObject load] for the order of things that happen around +load time. Everything listed there is before main(). – Rob Napier Dec 03 '13 at 00:31