mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-31 07:30:40 +00:00
better completion block handling
make sure to remove the completion block once done. This should help in cases the user forgot to do the weak-dance as well as when the copied objects are release
This commit is contained in:
parent
ff555cb87d
commit
c39053dbd2
@ -93,15 +93,16 @@
|
||||
}
|
||||
|
||||
- (void)setCompletion:(BITNetworkCompletionBlock)completion {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
if(nil == completion) {
|
||||
if(!completion) {
|
||||
[super setCompletionBlock:nil];
|
||||
} else {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[super setCompletionBlock:^{
|
||||
typeof(self) strongSelf = weakSelf;
|
||||
if(strongSelf) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completion(strongSelf, strongSelf->_data, strongSelf->_error);
|
||||
[strongSelf setCompletionBlock:nil];
|
||||
});
|
||||
}
|
||||
}];
|
||||
|
Loading…
x
Reference in New Issue
Block a user