weakSelf和strongSelf

    __weak typeof(self)weakSelf=self;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        __strong typeof(weakSelf)strongSelf=weakSelf;
        
        [strongSelf doSomething];
        
    });

 

 

weak typeof(self)weakSelf=self;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        __strong typeof(weakSelf)strongSelf=weakSelf;
        
        [strongSelf doSomething];
        
    });

 

weakSelf是为了block不持有self,避免循环引用,而再声明一个strongSelf是因为一旦进入block执行,就不允许self在这个执行过程中释放。block执行完后这个strongSelf会自动释放,没有循环引用问题。

posted on 2015-05-26 18:10  三十一  阅读(368)  评论(0编辑  收藏  举报

导航