0

why classes' +load() methods were invoked before project's main function? Is main function not the entrance of app? who invoked +load methods?

huangxinyu
  • 247
  • 3
  • 11

2 Answers2

1

First of all: It is +load, not load() (+load() doesn't syntactically exist), because it is a method, not a function.

main() is the entry point of an app. load is sent from the runtime environment, what obviously starts before the app is "started" by calling main().

In reality all class objects of a bundle gets a load message after loading the bundle. Obviously this is easier than having a flag for each class, whether it has already gotten the message.

However, that should not be a problem for your code, because the implementation +load should not rely on anything outside the class.

Amin Negm-Awad
  • 16,582
  • 3
  • 35
  • 50
-1

From: NSObject +load and +initialize - What do they do?

The runtime sends the load message to each class object, very soon after the class object is loaded in the process's address space. For classes that are part of the program's executable file, the runtime sends the load message very early in the process's lifetime.

jscs
  • 63,694
  • 13
  • 151
  • 195
Taier
  • 2,109
  • 12
  • 22