libextobjc
libextobjc copied to clipboard
How to weakify super access?
I don't wanna strong capture self in this block:
void(^block)() = ^{
[super someMethod];
};
Looks like I need to do something like this:
@weakify(self);
void(^block)() = ^{
@storngify(self);
[self.super someMethod];
};
But looks like this will not works as I want. I have solved this issue with this trick:
@weakify(self);
void(^block)() = ^{
@storngify(self);
[self superSomeMethod];
};
- (void)superSomeMethod {
[super someMethod];
}
Is there any way to achieve this without creating helper method?
I don't know of any, unfortunately. A similar problem affects ivar access that isn't explicitly done through self:
@weakify(self);
dispatch_block_t block = ^{
@strongify(self);
// whoops, retain cycle
[_someIvar doAThing];
}
I think you could do:
@weakify(self);
dispatch_block_t block = ^{
@strongify(self);
objc_msgSendSuper(&(struct objc_super){ self, [self superclass] }, @selector(someMethod));
}
You'll need to cast objc_msgSendSuper to the appropriate function pointer type.
@kastiglione heh, that looks really horrible!