Skip to content

Instantly share code, notes, and snippets.

Last active April 21, 2017 14:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Swift controller for a modal window / sheet; see
import Cocoa
class MyModalWindowController: NSWindowController {
var mainW: NSWindow = NSWindow()
override init() {
override init(window: NSWindow!) {
super.init(window: window)
//Initialization code here.
required init?(coder: (NSCoder!)){
super.init(coder: coder);
override func windowDidLoad() {
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
//method called to display the modal window
func beginSheet(mainWindow: NSWindow){
self.mainW = mainWindow
NSApp.beginSheet(self.window!, modalForWindow: mainWindow, modalDelegate: self, didEndSelector:nil, contextInfo: nil)
//method called, when "Close" - Button clicked
@IBAction func btnClicked(sender: AnyObject) {
//method called to slide out the modal window
func endSheet(){
Copy link

Alotabi1 commented Feb 6, 2017

#using namespace std;
int main ()

Copy link

Nice. You should update it to use NSWindow beginsheet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment