iosblockios9.2

Block is not getting executed


I have declared the method as follows:

- (void)downloadCSVs:(void (^)(void))completion

Its body is:

- (void)downloadCSVs:(void (^)(void))completion
{
        [[Singleton sharedData] downloadCSVFilesFromServer:<MY_URL>];
}

and calling this method as:

[self downloadCSVs:^
{
        NSLog(@"Download Completed!");
}];

But its after download, it is not executing the NSLog. Please let me know where I am wrong.


Solution

  • Your block isn't being called as there is no attempt to call it.

    The following method accepts the block as a parameter and, in turn, calls [Singleton downloadCSVFilesFromServer:] but it does not pass the block to this method and does not call it itself:

    - (void)downloadCSVs:(void (^)(void))completion
    {
        [[Singleton sharedData] downloadCSVFilesFromServer:<MY_URL>];
    }
    

    You need to extend the [Singleton downloadCSVFilesFromServer:] method to accept the block parameter and call it when it's complete.