title: Block until NSAlert (shown as a modal sheet) is dismissed
body: <p>I'm currently learning (by doing) objective-c by implementing a feature I felt is missing in the Titanium Appcelerator Desktop SDK: A way to do modal dialog with custom button texts and optionally to display them as a "sheet".</p>
  
  <p>All is dandy and working, however, when displaying the NSAlert as a "sheet" my method that's creating the alert returns immediately and that's what I want to prevent.</p>
  
  <p>The method's creating the alert returns an int (the return code from the NSAlert).</p>
  
  <p>The code inside basically boils down to:</p>
  
  <pre><code>int returnCode = -1;
  if (displayAsSheet) {
      [alert beginSheetModalForWindow:nativeWindow modalDelegate:delegate didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
  
  } else {
      returnCode = [alert runModal];
  }
  
  return returnCode;
  </code></pre>
  
  <p>The modalDelegate is an object that's implementing the needed:</p>
  
  <pre><code>- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
  </code></pre>
  
  <p>and for now it just does a NSLog of the returnCode.</p>
  
  <p>So my question is:</p>
  
  <p>How can I block my method from returning until the "sheet" has been dismissed?</p>
  
  <p>Or am I going about this the wrong way?</p>