Read return value from block

I have the following block defined in my class:

typedef BOOL (^AlertViewShouldEnableFirstOtherButtonHandler)(AlertView *alertView);

I call this block like so in my viewcontroller and return a boolean, as expected by the block.

 self.alertView.shouldEnableFirstOtherButtonHandler = ^BOOL (AlertView *alertView ) { 

     return YES; 
}

How would I manage to get/read the return value in my class?

Upvotes: 2

Views: 150

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727047

The only way of getting a return value from a block is to invoke it:

UIAlertView *av = [[UIAlertView alloc]
    initWithTitle:@"Quick brown"
    message:@"fox jumps"
    delegate:self
    cancelButtonTitle:@"over the"
    otherButtonTitles:@"Lazy dog",
    nil];
BOOL blockResult = self.alertView.shouldEnableFirstOtherButtonHandler(av);

Upvotes: 7

Related Questions