Skip to content

Instantly share code, notes, and snippets.

@okket okket/WebKit.swift

Created Jun 27, 2014
What would you like to do?
// WebKit Window in 30 lines of Swift code
// see
import Cocoa
import WebKit
let application = NSApplication.sharedApplication()
let window = NSWindow(contentRect: NSMakeRect(0, 0, 800, 600), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask, backing: .Buffered, defer: false)
window.title = "Minimal Swift WebKit Browser"
class WindowDelegate: NSObject, NSWindowDelegate {
func windowWillClose(notification: NSNotification?) {
let windowDelegate = WindowDelegate()
window.delegate = windowDelegate
class ApplicationDelegate: NSObject, NSApplicationDelegate {
var _window: NSWindow
init(window: NSWindow) {
self._window = window
func applicationDidFinishLaunching(notification: NSNotification?) {
let webView = WebView(frame: self._window.contentView.frame)
webView.mainFrame.loadRequest(NSURLRequest(URL: NSURL(string: "")))
let applicationDelegate = ApplicationDelegate(window: window)
application.delegate = applicationDelegate
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.