DCG语法

作者: 坐怀不乱的大叔 | 来源:发表于2015-07-28 10:22 被阅读30次

    后台执行:dispatch_async(dispatch_get_global_queue(0,0), ^{

    something});

    主线程执行:dispatch_async(dispatch_get_main_queue(), ^{

    something});

    一次性执行:staticdispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

    code to be executed once});

    延迟2秒执行:doubledelayInSeconds =2.0;

    dispatch_time_t popTime= dispatch_time(DISPATCH_TIME_NOW, delayInSeconds *NSEC_PER_SEC);

    dispatch_after(popTime, dispatch_get_main_queue(),^(void){//code to be executed on the main queue after delay});


    dispatch_queue_t 也可以自己定义,如要要自定义queue,可以用dispatch_queue_create方法,示例如下:

    dispatch_queue_t urls_queue = dispatch_queue_create("blog.devtang.com", NULL);

    dispatch_async(urls_queue,^{

    your code});

    dispatch_release(urls_queue);

    相关文章

      网友评论

          本文标题:DCG语法

          本文链接:https://www.haomeiwen.com/subject/dmdrqttx.html