title: Wait for [NSAlert beginSheetModalForWindow:...];
body: <p>When I display an NSAlert like this, I get the response straight away:</p>
  
  <pre><code>int response;
  NSAlert *alert = [NSAlert alertWithMessageText:... ...];
  response = [alert runModal];
  </code></pre>
  
  <p>The problem is that this is application-modal and my application is document based. I display the alert in the current document's window by using sheets, like this:</p>
  
  <pre><code>int response;
  NSAlert *alert = [NSAlert alertWithMessageText:... ...];
  [alert beginSheetModalForWindow:aWindow
                    modalDelegate:self
                   didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
                      contextInfo:&amp;response];
  
  //elsewhere
  - (void) alertDidEnd:(NSAlert *) alert returnCode:(int) returnCode contextInfo:(int *) contextInfo
  {
      *contextInfo = returnCode;
  }
  </code></pre>
  
  <p>The only issue with this is that <code>beginSheetModalForWindow:</code> returns straight away so I cannot reliably ask the user a question and wait for a response. This wouldn't be a big deal if I could split the task into two areas but I can't.</p>
  
  <p>I have a loop that processes about 40 different objects (that are in a tree). If one object fails, I want the alert to show and ask the user whether to continue or abort (continue processing at the current branch), but since my application is document based, the Apple Human Interface Guidelines dictate to use sheets when the alert is specific to a document.</p>
  
  <p>How can I display the alert sheet and wait for a response?</p>