Can I call a block inside a block, with both blocks being inside a method in iOS?

143 views Asked by At

In my iOS project i call a method that contains 2 blocks say A & B. Both blocks perform 2 different network calls, A goes first and based on some network response, executes block B. I've done so for tidiness since both do a lot of stuff & I've seen this work in my project but I'm not sure if it is correct to do so. Some illustration:

// somewhere in code
...
[self methodThatContainsTwoBlocks];
...

- (void)methodThatContainsTwoBlocks {

    Block B ^(responseFromSingletonOperation) {
       // do another network operation
       [MyNetworkManagerSingleton performAnotherOperationAsynchronouslyWithCompletion:^{
       // call some method when done  
       [self wereDone];
       }
    }

    [MyNetworkManagerSingleton performAnOperationAsynchronouslyWithCompletion:^{
      // do a network operation
      // call block B with response
      B(responseFromNetworkOperation);

    }
}

The phrasing of my question may not be correct since the networking singleton instance takes a completion block, hence my saying, two blocks. I hope the illustration makes my question clearer though as I've only just started iOS programming and still dabbling my way with blocks since senior devs recommend them a lot. Thanks.

0

There are 0 answers