0

Please consider this sample code:

- (long)someMethod {

   long returnValue;

   [MFPDFConverter createPDFFromEmail:emailToConvert completionHandler:^(long longObtainedFromBlock) {
        NSLog(@"Here we are");
        returnValue = longObtainedFromBlock;        
   }];

   return returnValue;

}

How can I refactor the method to wait for the block to end before returning the value ? Thanks for your attention.

Alfonso Tesauro
  • 1,730
  • 13
  • 21

1 Answers1

0

maybe put the return value in block

- (void)someMethod:(void(^)(long returnValue))callback {
   [MFPDFConverter createPDFFromEmail:emailToConvert completionHandler:^(long longObtainedFromBlock) {
        NSLog(@"Here we are");
       if (callback) {
           callback(longObtainedFromBlock);
       }
   }];
}
childrenOurFuture
  • 1,889
  • 2
  • 14
  • 23