With the following code:
@interface MyClass()
{
NSMutableArray * dataArray;
}
@end
@implementation MyClass
- (void) doSomething
{
__typeof__(self) __weak wself = self;
dispatch_async(dispatch_get_global_queue(0,0), ^{
__typeof__(self) sself = wself;
[sself->dataArray addObject: @"Hello World"];
dispatch_async(dispatch_get_main_queue(), ^{
[NSThread sleepForTimeInterval: 30];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: sself->dataArray[0]
message: @"Message"
delegate: nil
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
[alert show];
});
});
}
@end
sself from within the main queue block?sself go out of scope once the initial queue finished?__typeof__(self) sself = wself; inside the main queue block?__typeof__(self) sself = wself; even in global_queue block; it's not necessary, you already have a weakened self object wself (moreover, you will retain self in __typeof__(self) part inside the block).__typeof__. Use simply typeof(self)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With