现在的位置: 首页 > 综合 > 正文

简化只执行一次的写法

2018年05月25日 ⁄ 综合 ⁄ 共 347字 ⁄ 字号 评论关闭

标准的写法


简化后的宏

/**************************************************************/
// 执行一次
#undef  XY_ONCE_BEGIN
#define XY_ONCE_BEGIN( __name ) \
static dispatch_once_t once_##__name; \
dispatch_once( &once_##__name , ^{

#undef  XY_ONCE_END
#define XY_ONCE_END     });

简化后的写法

- (IBAction)clickOnce:(id)sender {
    XY_ONCE_BEGIN(a)
    SHOWMBProgressHUD(@"only show once", nil, nil, NO, 2)
    XY_ONCE_END
}

抱歉!评论已关闭.