Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
swift osx application without nib
import Cocoa
class WindowController: NSWindowController {
class AppDelegate: NSObject {
var mainWindow: NSWindow?
var mainController: NSWindowController?
extension AppDelegate {
@objc func quit(sender: NSMenuItem) {
extension AppDelegate: NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
let mainMenu = NSMenu()
let mainMenuFileItem = NSMenuItem(title: "File", action: nil, keyEquivalent: "")
let fileMenu = NSMenu(title: "File")
fileMenu.addItem(withTitle: "Quit", action: #selector(quit(sender:)), keyEquivalent: "q")
mainMenuFileItem.submenu = fileMenu
NSApp.mainMenu = mainMenu
let window = NSWindow(contentRect: NSMakeRect(1280, 960, 1280, 960), styleMask:[.titled, .closable, .resizable], backing: .buffered, defer: false)
window.backgroundColor = NSColor(calibratedRed: 0.1, green: 0.1, blue: 0.1, alpha: 1.0)
window.title = "App"
mainWindow = window
let controller = WindowController(window: window)
mainController = controller
NSApp.activate(ignoringOtherApps: true)
func applicationWillTerminate(_ aNotification: Notification) {
func applicationShouldTerminateAfterLastWindowClosed(_ app: NSApplication) -> Bool{
return true
let app = NSApplication.shared
let delegate = AppDelegate()
app.delegate = delegate
atexit_b { app.setActivationPolicy(.prohibited); return }
.PHONY: build
@DEVELOPER_DIR="/Applications/" SDKROOT="/Applications/" xcrun swiftc -o app app.swift && ./app

This comment has been minimized.

Copy link

@fnc12 fnc12 commented May 14, 2018

WindowController what is this?

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.