Created
August 30, 2019 22:10
-
-
Save ctreffs/5ad0b674bb1b03645a497c3ebb8013e1 to your computer and use it in GitHub Desktop.
Minimal Cocoa/AppKit Swift Package Manager application (SwiftPM)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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