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
?
In the latest clang version Apple clang version 4.0 (tags/Apple/clang-421.1.48) (based on LLVM 3.1svn), i.e. Xcode 4.4+, the __typeof__((__typeof__(self))self)
trick is not necessary anymore. The __weak typeof(self) bself = self;
line will compile just fine.