- initialize执行时机
- initialize的执行顺序和次数
@interface initTest : NSObject @end @interface sub1 : initTest @interface sub2 : sub1 @interface sub2 (category1) @interface sub2 (category2) @end @implementation initTest //+(void)initialize +(void)load @end @implementation sub1 +(void)initialize //+(void)load @implementation sub2 //+(void)initialize +(void)load @end @implementation sub2 (category1) //+(void)initialize +(void)load @end @implementation sub2 (category2) //+(void)initialize +(void)load @end |
2015-05-26 13:44:58.757 OCinitTest[80219:72734510] +[initTest load] 2015-05-26 13:44:58.758 OCinitTest[80219:72734510] +[sub2 load] 2015-05-26 13:44:58.759 OCinitTest[80219:72734510] +[sub2(category1) load] 2015-05-26 13:44:58.759 OCinitTest[80219:72734510] +[sub2(category2) load] 2015-05-26 13:44:58.863 OCinitTest[80219:72734510] +[sub1 initialize]|sub1 2015-05-26 13:44:58.863 OCinitTest[80219:72734510] +[sub1 initialize]|sub2 2015-05-26 13:44:58.863 OCinitTest[80219:72734510] +[sub1 initialize]|NSKVONotifying_sub2 |
- initialize的作用
static MySingleton *sharedSingleton;
+ (void)initialize
{
static BOOL initialized = NO;
if(!initialized)
{
initialized = YES;
sharedSingleton = [[MySingleton alloc] init];
}
}