Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swift Script Error - Permission denied
./webkit.swift
-bash: ./webkit.swift: Permission denied

add x permision on it chmod +x webkit.swift

#!/usr/bin/env xcrun swift -v
import WebKit
let application = NSApplication.sharedApplication()
application.setActivationPolicy(NSApplicationActivationPolicy.Regular)
let window = NSWindow(contentRect: NSMakeRect(0, 0, 800, 600), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask, backing: .Buffered, defer: false)
window.center()
window.title = "Minimal Swift WebKit Browser"
window.makeKeyAndOrderFront(window)
class WindowDelegate: NSObject, NSWindowDelegate {
func windowWillClose(notification: NSNotification) {
NSApplication.sharedApplication().terminate(0)
}
}
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)
self._window.contentView.addSubview(webView)
webView.mainFrame.loadRequest(NSURLRequest(URL: NSURL(string: "https://www.gooogle.com/ncr")!))
}
}
let applicationDelegate = ApplicationDelegate(window: window)
application.delegate = applicationDelegate
application.activateIgnoringOtherApps(true)
application.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment