0
votes

Showing an error like this some problem with the completion block return type.

 -(NSDictionary*)makeWebServiceCallAmmendments
{   
    __block NSDictionary*DicWebResponsePersonel;
    NSMutableDictionary *DictAppPatData=[PatientData sharedManager:nil];
    NSString*StrUrlContact=[NSString stringWithFormat:@"%@patient/getPatientDetails?pid=%@&type=ammendments",MainUrlUPDATEServer,[DictAppPatData objectForKey:@"pid"]];
    NSURL*url=[NSURL URLWithString:StrUrlContact];
    MBProgressHUD *hud= [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:hud];
    hud.labelText = @"Please wait...";
    [hud showAnimated:YES whileExecutingBlock:^(void)
     {
        DicWebResponsePersonel=[[SRUtility sharedManager]makeWebServicecallForGetmethod:url];         
     } completionBlock:^(void)
     {
         return DicWebResponsePersonel;
     }];
}   

in completionBlock showing error like incompatible block pointer types sending ‘nsdictionary’(^)(void)’to parameter of type ‘MBProgressHUDCompletionBlock’(aka ‘void(^)()’)

1
Please share some code so other can give you answer.Abhishek Sharma
Please provide details, we can not guess your issue. Code, stacktrace whatever helps understanding ...dogsgod
Please share the code for the help?Karthikeyan.R.S
Look at your post. Do you think anyone is willing to read it?gnasher729
I am new in posting questions in stackoverflow sorry for the inconvinince.Now i think its in the proper way.sreejith sr

1 Answers

0
votes

Because completionBlock return type is void. So completionBlock can't return any value.

typedef void (^MBProgressHUDCompletionBlock)();
- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(MBProgressHUDCompletionBlock)completion;

Anyway, you want to make makeWebServiceCallAmmendments method returns DicWebResponsePersonel? It is not good idea.

According to MBProgressHUD header, whileExecutingBlock is executed on a background queue, and completionBlock is executed on completion of whileExecutingBlock.

/**
 * Shows the HUD while a block is executing on a background queue, then hides the HUD.
 *
 * @see showAnimated:whileExecutingBlock:onQueue:completionBlock:
 */
- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(MBProgressHUDCompletionBlock)completion;

...

 * @param block The block to be executed while the HUD is shown.
 * @param completion The block to be executed on completion.

Your code would be executed like the following.

-(NSDictionary*)makeWebServiceCallAmmendments
{   

    /*
     * This method call is invoked on the main queue
     */

    ...

    [hud showAnimated:YES whileExecutingBlock:^(void) {

        /*
         * This block is invoked on a background queue.
         * It will take long time.
         */ 

        DicWebResponsePersonel=[[SRUtility sharedManager]makeWebServicecallForGetmethod:url];         

     } completionBlock:^(void) {

        /*
         * This block is invoked on the main queue after the previous whileExecutingBlock finished
         */

         // return DicWebResponsePersonel;

     }];

     /*
      * Want to return DicWebResponsePersonel!
      * Have to wait the completionBlock finished!
      */
}

So, your makeWebServiceCallAmmendments method have to wait the completionBlock was invoked in order to return DicWebResponsePersonel value. But it also means block the main thread long time. Totally bad app. You should avoid this way.