简化只执行一次的写法

2014-11-23 22:28:00 · 作者: · 浏览: 0

标准的写法


简化后的宏

/**************************************************************/

// 执行一次

#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

}