iOS模塊化之路(一)

人們往往會在appDelegate中的方法中引入一些其它模塊的初始化工作。但是這造成了代碼的雜亂。其實可以通過NSNotification在自己的模塊中完成初始化。
/// FooModule.m
+ (void)load
{
    __block id observer =
    [[NSNotificationCenter defaultCenter]
     addObserverForName:UIApplicationDidFinishLaunchingNotification
     object:nil
     queue:nil
     usingBlock:^(NSNotification *note) {
         [self setup]; // Do whatever you want
         [[NSNotificationCenter defaultCenter] removeObserver:observer];
     }];
}

參考自sunnyxx
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章