Referring to weak self inside a nested block

前端 未结 2 379
一整个雨季
一整个雨季 2020-12-01 03:00

Suppose I already create a weak self using

__weak typeof(self) weakSelf = self;
[self doABlockOperation:^{
        ...
}];

Inside that bloc

2条回答
  •  抹茶落季
    2020-12-01 03:33

    It depends.

    You only create a retain cycle if you actually store the block (because self points to the block, and block points to self). If you don't intend to store either of the blocks, using the strong reference to self is good enough --- block will be released first after it got executed, and then it will release it's pointer to self.

    In your particular example, unless you're performing more operations which are not shown, you don't need to create any weakerWeakerEvenWeakerSelfs.

提交回复
热议问题