The runtime sends initialize to each classin a program just before the class, or any class that inherits from it, is sent its first message from within the program. Superclasses receive this message before their subclasses.
The runtime sends the initialize messageto classes in a thread-safe manner. That is, initialize is run by the first thread to send a messageto a class, and any other thread that tries to send a messageto that class will block until initialize completes.
The superclass implementation may be called multiple times if subclasses donot implement initialize—the runtime will call the inheritedimplementation—orif subclasses explicitly call [super initialize]. If you want to protect yourself from being run multiple times, you can structure your implementation along these lines: + (void)initialize { if (self == [ClassName self]) { // ... do the initialization ... } }
Because initialize is called in a blocking manner, it’s important to limit method implementations to the minimum amount of work necessary possible. Specifically, any code that takes locks that might be required by other classes in their initialize methods is liable to lead to deadlocks. Therefore, you should not rely on initialize for complex initialization, and should instead limit it to straightforward, classlocalinitialization.
Special Considerations initialize is invoked only once per class. If you want to perform independent initializationfor the classandfor categories of the class, you should implement load methods.