弱自引用的泛型typeof [英] Generic typeof for weak self references
问题描述
我试图找出一种方法使用 typeof
创建一个弱引用 self
块,以避免保留周期。
当我第一次读到这个,似乎约定是使用 __ block typeof(self)bself = self;
,它使用
__ block
进行编译,以避免保留周期不再工作, __ weak
但是 __ weak typeof(self)bself = self;
会导致错误:
类型'typeof(self)'(也称为'TUAccountsViewController * const __strong')已经设置了保留属性
$ b
有没有办法使用 typeof
或另一个调用来通常创建一个弱引用 self
这样有效!
__ typeof __(o)__weak
我在我的BBlock项目中定义了 BBlockWeakSelf
可以这样使用:
BBlockWeakSelf wself = self;
https://github.com/kgn/BBlock/blob/master/BBlock.h
根据Aleph7编辑回应。
I am trying to figure out a way to use typeof
to create a weak reference to self
for use in blocks to avoid retain cycles.
When I first read about this it seems that the convention was to use __block typeof(self) bself = self;
, which compiles but using __block
to avoid retain cycles doesn't work anymore and __weak
should be used instead.
However __weak typeof(self) bself = self;
results in an error:
The type 'typeof (self)' (aka 'TUAccountsViewController *const __strong') already has retainment attributes set on it
Is there a way to use typeof
or another call to generically create a weak reference to self
?
This works!
__typeof__(o) __weak
Which I've defined in my BBlock project as BBlockWeakSelf
which can be used like this:
BBlockWeakSelf wself = self;
https://github.com/kgn/BBlock/blob/master/BBlock.h
Edited based on Aleph7's response.
这篇关于弱自引用的泛型typeof的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!