iOS ---GCD

dispatch_async 异步执行

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

// 耗时操作

dispatch_async(dispatch_get_main_queue(), ^{

// 更新界面

});

});

dispatch_once 一次执行

+ (instancetype)defaultInfoCenter {

static InfoCenter *infoCenter = nil;

static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

infoCenter = [[InfoCenter alloc] init];

});

return infoCenter;

}

dispatch_after 延迟执行

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

NSLog(@"在5s后执行");

});

你可能感兴趣的:(iOS ---GCD)