iOS——系统提供的dispatch方法

时间:2015-04-05 11:53:40   收藏:0   阅读:324

// 后台执行:

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

});

原文:http://www.cnblogs.com/congzhong/p/4393821.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!