zoukankan      html  css  js  c++  java
  • GCD

    总是习惯把知识记录在本地,是时候改变一下存储知识的方式了,丰富自己,帮助他人!

    1.GCD 的一般用法

         dispatch_async(dispatch_get_global_queue(00), ^{

       //耗时操作。。

          

            dispatch_async(dispatch_get_main_queue(), ^{        

       //通知主线程刷新

            })

    });

     

     

    2.用GCD做定时器 

    @property (nonatomic) dispatch_source_t timerSource;

    - (void)updateWithInte:(NSInteger) time{

        NSTimeInterval period = time; //设置时间间隔

        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

        _timerSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);

        dispatch_source_set_timer(_timerSource, dispatch_walltime(NULL, 0), period * NSEC_PER_SEC, 0); //每秒执行

        dispatch_source_set_event_handler(_timerSource, ^{

            NSLog(@"nihao");

        });

        dispatch_resume(_timerSource);

    }

    作者:啡色的灰机------------------------------------------------------------------------------------------------------------ 邮箱:developer_yh@163.com--------------------------------------------------------------------------------------------- GitHub:https://github.com/developeryh
  • 相关阅读:
    c++入门之初话结构体
    c++学习之字符串拼接
    数组赋值问题
    c++之sizeof的用法
    MySQL 创建一个简单的成绩管理系统
    KMP算法详解
    [Leetcode] Implement strstr
    [Leetcode] Multiply strings 字符串对应数字相乘
    [Leetcode] count and say 计数和说
    [Leetcode] Roman to integer 罗马数字转成整数
  • 原文地址:https://www.cnblogs.com/devyh/p/5313506.html
Copyright © 2011-2022 走看看