OC中有两个特殊的类方法,分别是load和initialize.本文总结一下这两个方法的区别于联系.使用场景和注意事项.Demo可以在我的Github上找到--load和initialize,如果觉得有帮助还望点个关注以示支持,总结在文章末尾. 先来看看NSObject Class Reference里对这两个方法说明: +(void)initialize The runtime sends initialize to each class in a program exactly one ti…
NSObject是一切OC类的基类,所以我们必须对NSObject所有的方法有一个清楚的认识. + (void)load; 当类或者分类被加入到runtime时,load方法会被调用,也就是说在main循环开始前load方法就已经被调用. (当类被加载到进程的address space时,runtime就会给每个类发送load消息.For classes that are in a shared (dynamically-loaded) library, the runtime sends th…
这篇文章来对比一下NSObject类的两个方法,+load与+initialize. + (void)load; Invoked whenever a class or category is added to the Objective-C runtime; implement this method to perform class-specific behavior upon loading. 不管一个类.类别是被动态加载或者静态链接,都会被发送load消息,但是只有新加入的类或者类别实现…
+ (void)initializeDescription(描述) Initializes the class before it receives its first message. 在这个类第一次接受信息之前初始化这个类. The runtime sends initialize to each class in a program just before the class, or any class that inherits from it, is sent its first…