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.

Revisions

  1. vinbrule created this gist Jul 22, 2020.
    24 changes: 24 additions & 0 deletions load webarchieve locally swift mac.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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