Last active
November 15, 2015 19:49
-
-
Save c9iim/c902b19847251383b9d1 to your computer and use it in GitHub Desktop.
コマンドプロンプトで「$ swift ./minimal-app.swift」とすれば実行可能。パッケージ化の手順は後で別途記述。
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 Cocoa | |
// ApplicationDelegate | |
class ApplicationDelegate: NSObject, NSApplicationDelegate { | |
var window: NSWindow! | |
init(window: NSWindow) { | |
self.window = window | |
} | |
func applicationDidFinishLaunching(aNotification: NSNotification) { | |
// Insert code here to initialize your application | |
NSApp.activateIgnoringOtherApps(true) | |
window.center() | |
window.makeKeyAndOrderFront(window) | |
} | |
func applicationWillTerminate(aNotification: NSNotification) { | |
// Insert code here to tear down your application | |
} | |
func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool { | |
return true | |
} | |
} | |
// WindowDelegate | |
class WindowDelegate: NSObject, NSWindowDelegate { | |
func windowWillClose(aNotification: NSNotification) { | |
// Insert code here to close your application's window | |
} | |
} | |
// Application Name | |
let appName = NSProcessInfo.processInfo().processName | |
//// Window | |
let windowContent = NSMakeRect(0, 0, 480, 360) | |
let windowStyle = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask | |
let windowDelegate = WindowDelegate() | |
let window = NSWindow(contentRect: windowContent, styleMask: windowStyle, backing: .Buffered, `defer`: false) | |
window.title = appName | |
window.delegate = windowDelegate | |
// Menu | |
let menuBar = NSMenu() | |
let menuItem = NSMenuItem() | |
let menuApp = NSMenu() | |
let menuQuitTitle = "Quit \(appName)" | |
let menuQuitItem = NSMenuItem(title:menuQuitTitle, action: "terminate:", keyEquivalent: "q") | |
menuApp.addItem(menuQuitItem) | |
menuItem.submenu = menuApp | |
menuBar.addItem(menuItem) | |
// Application | |
let application = NSApplication.sharedApplication() | |
let applicationDelegate = ApplicationDelegate(window: window) | |
application.setActivationPolicy(NSApplicationActivationPolicy.Regular) | |
application.mainMenu = menuBar | |
application.delegate = applicationDelegate | |
application.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment