Q:

Make UIAlertView blocking

I need make UIAlertView blocking.  Because i have function and i need to return UIAlertView choice.  But problem is that after UIAlertView is shown my function code is executing further so i can't catch UIAlertView choice (i can do it in delegate methods, but i need to return function result). 
I tried to make UIAlertVIew blocking with NSCondition.  But the code don't works. 
condition = [NSCondition new];
result = 0 ; 
[condition lock];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Fingerprint" message:@"test" delegate:window_self cancelButtonTitle:@"No" otherButtonTitles:@"Yes",nil];
[alert setDelegate:self];
[alert show];
while (result == 0) [condition wait];
[condition unlock] ;

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
 [condition lock] ;
 if (buttonIndex == 0)
 {
  result = 2; 
 }
 else if (buttonIndex == 1)
 {
  result = 3 ;
 }
 [condition signal] ;
 [condition unlock] ;
}

Maybe how to fix this code or any other suggestions ?  Thanks

A:

There's no way to achieve what you want.  Only through the delegate.  You should redesign your function or refuse using UIAlertView

A:

This doesn't make it blocking, but I have written a subclass to add block style syntax which makes it much easier to handle the buttonClickedAtIndex method without having to do a delegate and a whole bunch of if statements if you have multiple UIAlertViews in one class.  
#import <UIKit/UIKit.h>

@interface UIAlertViewBlock : UIAlertView<UIAlertViewDelegate>
- (id) initWithTitle:(NSString *)title message:(NSString *)message block: (void (^)(NSInteger buttonIndex))block
   cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_AVAILABLE(10_6, 4_0);
@end

#import "UIAlertViewBlock.h"

@interface UIAlertViewBlock()
{
    void (^_block)(NSInteger);
}
@end

@implementation UIAlertViewBlock

- (id) initWithTitle:(NSString *)title message:(NSString *)message block: (void (^)(NSInteger buttonIndex))block
cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_AVAILABLE(10_6, 4_0)
{
    if (self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles, nil])
    {
        _block = block;
    }
    return self;
}

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    _block(buttonIndex);
}

@end

Then to call it here is some example code.  The other cool part is that because a block closes around the local variables, I can have access to all the state that existed at the time I show the UIAlertView.  Using the traditional delegate approach, you would have to store all that temporary state into class level variables to have access to it in the call to buttonClickedAtIndex in the delegate.  This is so much cleaner. 
{
    NSString *value = @"some random value";
    UIAlertViewBlock *b = [[UIAlertViewBlock alloc] initWithTitle:@"Title" message:@"Message" block:^(NSInteger buttonIndex)
        {
            if (buttonIndex == 0)
                NSLog(@"%@", [value stringByAppendingString: @" Cancel pressed"]);
            else if (buttonIndex == 1)
                NSLog(@"Other pressed");
            else
                NSLog(@"Something else pressed");
        }
        cancelButtonTitle:@"Cancel" otherButtonTitles:@"Other", nil];

    [b show];
}

