- load方法的执行时机
- load的执行次序
/*********************************************************************** * _class_getLoadMethod * fixme * Called only from add_class_to_loadable_list. * Locking: runtimeLock must be read- or write-locked by the caller. **********************************************************************/ IMP _class_getLoadMethod(Class cls_gen) {rwlock_assert_locked(&runtimeLock);class_t *cls = newcls(cls_gen);const method_list_t *mlist;uint32_t i;assert(isRealized(cls));assert(isRealized(cls->isa));assert(!isMetaClass(cls));assert(isMetaClass(cls->isa));mlist = cls->isa->data()->ro->baseMethods;if (mlist) for (i = 0; i < mlist->count; i++) {method_t *m = method_list_nth(mlist, i);if (0 == strcmp((const char *)m->name, "load")) {return m->imp;}}return NULL; } |
@interface initTest : NSObject @end @interface sub1 : initTest @end @interface sub2 : sub1 @end @interface sub2 (category1) @end @interface sub2 (category2) @end //实现 @implementation initTest //+(void)initialize //{ // NSLog(@"%s|%@ ",__func__ ,[self class]); //} +(void)load { NSLog(@"%s ",__func__ ); } @end @implementation sub1 //+(void)initialize //{ // NSLog(@"%s|%@ ",__func__ ,[self class]); //} //+(void)load //{ // NSLog(@"%s ",__func__ ); //} @end @implementation sub2 //+(void)initialize //{ // NSLog(@"%s|%@ ",__func__ ,[self class]); //} +(void)load { NSLog(@"%s ",__func__ ); } @end @implementation sub2 (category1) +(void)load { NSLog(@"%s ",__func__ ); } @end @implementation sub2 (category2) +(void)load { NSLog(@"%s ",__func__ ); } @end |
2015-05-26 13:09:37.955 OCinitTest[79585:72506319] +[initTest load] 2015-05-26 13:09:37.956 OCinitTest[79585:72506319] +[sub2 load] 2015-05-26 13:09:37.956 OCinitTest[79585:72506319] +[sub2(category1) load] 2015-05-26 13:09:37.956 OCinitTest[79585:72506319] +[sub2(category2) load] |
- load方法可以用来做什么