Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vinbrule/fdce5cf7e221f34d2e400bfada502438 to your computer and use it in GitHub Desktop.
Save vinbrule/fdce5cf7e221f34d2e400bfada502438 to your computer and use it in GitHub Desktop.
load webarchieve locally swift mac
import AppKit
import PlaygroundSupport
import WebKit
var webView: WKWebView!
webView = WKWebView(frame: CGRect(x: 0, y: 0, width: 600, height: 800.0))
var filePath = URL.init(fileURLWithPath: "/Users/van/Downloads/firefox/01-interview preparation/leetcode/facebook/Longest Substring Without Repeating Characters - LeetCode Articles.webarchive")
print(filePath)
let fileDirectoryURL = filePath.deletingLastPathComponent()
webView.loadFileURL(filePath, allowingReadAccessTo: fileDirectoryURL)
//if let url = URL(string: "https://www.apple.com") {
// let request = URLRequest(url: url)
// webView.load(request)
//}
let nibFile = NSNib.Name("MyView")
var topLevelObjects : NSArray?
Bundle.main.loadNibNamed(nibFile, owner:nil, topLevelObjects: &topLevelObjects)
let views = (topLevelObjects as! Array<Any>).filter { $0 is NSView }
// Present the view in Playground
PlaygroundPage.current.liveView = webView//views[0] as! NSView
@vinbrule
Copy link
Author

Past it into the playground and see the results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment