Skip to content

Instantly share code, notes, and snippets.

@ctreffs
Created August 30, 2019 22:10
Show Gist options
  • Save ctreffs/5ad0b674bb1b03645a497c3ebb8013e1 to your computer and use it in GitHub Desktop.
Save ctreffs/5ad0b674bb1b03645a497c3ebb8013e1 to your computer and use it in GitHub Desktop.
Minimal Cocoa/AppKit Swift Package Manager application (SwiftPM)
import AppKit
_ = NSApplication.shared
NSApp.setActivationPolicy(.regular)
//let delegate = AppDelegate()
//NSApplication.shared.delegate = delegate
let menubar = NSMenu()
let appMenuItem = NSMenuItem()
menubar.addItem(appMenuItem)
NSApp.mainMenu = menubar
let appMenu = NSMenu()
let appName = ProcessInfo.processInfo.processName
let quitTitle = "Quit \(appName)"
let quitMenuItem = NSMenuItem(title: quitTitle,
action: #selector(NSApplication.shared.terminate(_:)),
keyEquivalent: "q")
appMenu.addItem(quitMenuItem)
appMenuItem.submenu = appMenu
let window: NSWindow = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 800, height: 600),
styleMask: [.titled, .closable, .miniaturizable, .resizable],
backing: .buffered,
defer: false)
window.center()
window.title = appName
window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
NSApp.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment