Is this safe to do ?
#define wvar __weak __auto_type
and then usage
wvar _self = self;
_filterMenuItem = [self addMenuItem:@"Filter" :^{
[_self.filterWithHeader toggleVisible];
}];
Safe. The critical part is that the variable is declared __weak
. So long as you then use it as an instance of self
-- and not some other class -- the runtime doesn't care what type the compiler thought it was (and in this case, the compiler will know that __auto_type
is the right type).
Remember also that the weak qualifier is only required if self
directly or indirectly retains the block in which it is referenced. For many blocks, plain old self
is safe from retain cycles.