@interface ViewController ()
@property (nonatomic,assign) BOOL hasExecuted;
@property (nonatomic,strong) ImageDownloader *imageDownloader;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// self.imageDownloader = [[ImageDownloader alloc] init];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/*
if (self.hasExecuted) {
return;
}
NSLog(@"下载图片");
self.hasExecuted = YES;
*/
// ImageDownloader *imageDownloader = [[ImageDownloader alloc] init];
// [imageDownloader download];
// [self.imageDownloader download];
NSLog(@"touchBegin");
static dispatch_once_t onceToken;
// 保证只执行一次
dispatch_once(&onceToken, ^{
NSLog(@"once");
});
NSLog(@"touchEnd");
/** 点击两次
* 2015-08-10 17:26:23.219 10 - 一次性代码[5583:156692] touchBegin
2015-08-10 17:26:23.221 10 - 一次性代码[5583:156692] once
2015-08-10 17:26:23.221 10 - 一次性代码[5583:156692] touchEnd
2015-08-10 17:26:23.963 10 - 一次性代码[5583:156692] touchBegin
2015-08-10 17:26:23.963 10 - 一次性代码[5583:156692] touchEnd
*/
}
GCD一次性代码
最新推荐文章于 2022-11-12 21:48:46 发布
