懒加载

宏式懒加载

定义一个懒加载的宏
#define DYJ_LAZY(object, assignment) (object = object ?: assignment)
使用

//使用
- (UINavigationBar *)navBar
{
    return DYJ_LAZY(_navBar, ({
        
        UINavigationBar *bar = [[UINavigationBar alloc] init];
        bar.barStyle = UINavigationBar.appearance.barStyle;
        bar.translucent = YES;
        [self.view addSubview:bar];
        [bar setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
        bar;
    }));
}

你可能感兴趣的:(懒加载)