iOS——系统提供的dispatch方法
// 后台执行:
dispatch_async(dispatch_get_global_queue(0,0), ^{
// something
});
// 主线程执行:
dispatch_async(dispatch_get_main_queue(),^{
// something
});
// 一次性执行:
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// code to be excuted once
});
// 延迟2秒执行:
double delayInSeconds = 2.0;
dispatch_time_y popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// code to be excuted on the main queue after delay
});