title: NSWindow beginSheet:completionHandler With No Response Buttons
body: <p>I understand that <code>NSApp</code>'s <code>beginSheet:modalForWindow</code> is deprecated for OS X 10.10.  So I need a replacement for it.  The thing is that I only want to show a window sheet with a progress wheel and <strong>no okay or cancel buttons</strong> while some work is under way with <code>performSelectorOnMainThread:withObject:waitUntilDone</code>.  Anyway, I have written the following lines of code for Objective-C and Swift.</p>
  
  <pre><code>- (void)Backgroundwork :(NSWindow *)window :(NSString *)labelMsg {
      NSRect sheetRect = NSMakeRect(0,0,400,114);
      NSWindow *progSheet = [[NSWindow alloc] initWithContentRect:sheetRect styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:YES];
      NSView *contentView = [[NSView alloc] initWithFrame:sheetRect];
      NSProgressIndicator *progInd = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(190,74,20,20)];
      [progInd setStyle:NSProgressIndicatorSpinningStyle];
  
      NSTextField *messageLabel = [[NSTextField alloc] initWithFrame:NSMakeRect(20,20,240,46)];
      messageLabel.stringValue = labelMsg;
      [messageLabel setBezeled:NO];
      [messageLabel setDrawsBackground:NO];
      [messageLabel setEditable:NO];
      [messageLabel setSelectable:NO];
      [contentView addSubview:messageLabel];
      [contentView addSubview:progInd];
      [progSheet setContentView:contentView];
  
      [window beginSheet:progSheet completionHandler:^(NSModalResponse returnCode) {
          // some work        
      }];
  }
  
  func Backgroundwork(window:NSWindow,labelMsg:String) -&gt; Void {
      let sheetRect:NSRect = NSMakeRect(0,0,400,114)
      let progSheet:NSWindow = NSWindow.init(contentRect:sheetRect, styleMask:NSTitledWindowMask,backing:NSBackingStoreType.Buffered,`defer`:true)
      let contentView:NSView = NSView.init(frame:sheetRect)
      let progInd:NSProgressIndicator = NSProgressIndicator.init(frame:NSMakeRect(190,74,20,20))
      progInd.style = NSProgressIndicatorStyle.SpinningStyle
      let msgLabel:NSTextField = NSTextField.init(frame:NSMakeRect(20,20,240,46))
      msgLabel.stringValue = labelMsg;
      msgLabel.bezeled = false
      msgLabel.drawsBackground = false
      msgLabel.editable = false
      msgLabel.selectable = false
      contentView.addSubview(msgLabel)
      contentView.addSubview(progInd)
      progSheet.contentView = contentView
  
      window.beginSheet(progSheet) {(NSModalResponse) -&gt; Void in
          // some work  
      }
  }
  </code></pre>
  
  <p>If I'm correct, <code>NSWindow</code>'s <code>beginSheet:completionHandler</code> requires response buttons.  So the application never enters the beginSheet bloc in the code above.  Right?  Or can I still use <code>beginSheet:completionHandler</code> without response (okay,cancel) buttons?  Or do I have to use something else other than beginSheet like a modal window that I have to open and close?</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <h2>Update 1</h2>
  
  <p>Maybe, making it a modal window with NSModalSession is the best alternative?</p>
  
  <pre><code>let session:NSModalSession = NSApp.beginModalSessionForWindow(progSheet)
  </code></pre>
  
  <p>This approach seems to conform to OS X 10.10.</p>