美文网首页
weakSelf 或 strongSelf

weakSelf 或 strongSelf

作者: 武个武6个武 | 来源:发表于2017-05-19 17:59 被阅读0次

在block中为了防止循环引用会使用weakSelf 或者 strongSelf
那么什么时候使用weakSelf,什么时候使用strongSelf;

1.如果block内部需要访问self的方法,属性或者实例变量需要使用weakSelf;
2.如果在block内需要多次访问self,则需要使用strongSelf
3.如果在block内部存在多线程环境访问self,则需要使用strongSelf

__weak typeof(self)weakSelf = self;
_collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        __strong typeof(self)strongSelf = weakSelf;
        dispatch_async(dispatch_get_main_queue(), ^{
            [strongSelf loadData];
        });
    }];

相关文章

  • RN 调 js 核心代码

    ^{RCTJSCExecutor *strongSelf = weakSelf;if (!strongSelf |...

  • weakSelf 或 strongSelf

    在block中为了防止循环引用会使用weakSelf 或者 strongSelf那么什么时候使用weakSelf,...

  • 宏定义

    1.weakSelf和strongSelf

  • 不一样的书写样式

    **********************1.block中weakSelf 与 strongSelf******...

  • StrongSelf

    weakSelf : 防止循环引用 strongSelf: 防止释放 需要 强引用weakSelf,主要是处理一...

  • weakSelf/strongSelf

    1.Retain Circle的由来 当A对象里面强引用了B对象,B对象又强引用了A对象,这样两者的retainC...

  • weakSelf & strongSelf

    循环引用 循环引用不做过多的解释,两个对象互相持有对方,谁都无法先被释放掉。循环引用经常是由于使用block而引起...

  • weakSelf strongSelf

    解决 retain circle Apple 官方的建议是,传进 Block 之前,把 ‘self’ 转换成 we...

  • iOS宏定义

    1 weakself和strongself #ifndef weakify #if DEBUG #ifhas_fe...

  • ObjC的Block中使用weakSelf/strongSelf

    学习block帖子ObjC的Block中使用weakSelf/strongSelf @weakify/@stron...

网友评论

      本文标题:weakSelf 或 strongSelf

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