Skip to content

Instantly share code, notes, and snippets.

@zentrope zentrope/AppDelegate.swift
Last active Jun 19, 2019

What would you like to do?
Open a window programmatically
// AppDelegate.swift
import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {
private var preferencesWindow = NSWindowController()
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
@IBAction func openPreferencesWindow(_ sender: NSMenuItem) {
if let _ = preferencesWindow.window {
let content = PreferencesViewController()
let window = NSWindow(contentRect: .zero, styleMask: [.titled, .closable], backing: .buffered, defer: true)
window.contentViewController = content
window.windowController = preferencesWindow
window.title = "Preferences"
preferencesWindow.window = window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.