ios – Correct use of strongSelf / weakSelf in nested dispatch_after blocks

0
38


I’ve an advanced launch and I must current and dismiss a number of view controllers. I’ve this little bit of code the place I would like to make use of delays in presentation; I used to be questioning if my use of strongSelf / weakSelf was correct within the following code with these dispatch_after blocks, or if there are enhancements that I ought to make to the code. I do know it is outdated Goal-C, I’m working with an previous, massive code base.

__weak typeof(self) weakSelf = self;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{//CURRENT
    
    __strong typeof(self) strongSelf = weakSelf;
    
    [strongSelf presentViewController:strongSelf.coverVC animated:NO completion:^{
        
        [strongSelf showWindowWithImage:NO];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            __strong typeof(self) strongSelf2 = weakSelf;

            [strongSelf2 dismissViewControllerAnimated:YES completion:^{

                strongSelf2.coverVC = nil;
                [strongSelf2 hideWindow];
            }];
        });
    }];
});