GCD block 的简单用法

来源:互联网 发布:linux获取cpu型号 编辑:程序博客网 时间:2024/05/22 17:18

1. block的引用指针对象变量, 可以这样转换: 

__weak typeof(self) weakSelf =self

或者   __unsafe_unretainedJNViewController *this =self; (貌似第一种方法更好记些)

2. GCD block的延时调用 (貌似用GCD写更装逼一些)

<span style="font-size:14px;">    // 延迟2秒执行:    double delayInSeconds = 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    });</span>

0 0
原创粉丝点击