Reputation: 85
I have done with codes below but I'm having problem loading the webview
with an url which show an error with on runtime
Thread 1:signal SIGABRT
so please help me with, i have just started with macOS
application development,
Thanks,
import Cocoa
import WebKit
class ViewController: NSViewController, WebFrameLoadDelegate {
@IBOutlet weak var webView: WebView!
let urlpath = NSURL(string: "http://www.google.com/")!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//let url = "https:www.apple.com"
//self.webView.mainFrame.load(NSURLRequest(URL: NSURL(string: url)! as URL))
webView.policyDelegate = self as! WebPolicyDelegate
webView.mainFrame.load(NSURLRequest(url: self.urlpath as URL ) as URLRequest!)
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
Upvotes: 0
Views: 491
Reputation: 2249
You don't implement the WebPolicyDelegate so
webView.policyDelegate = self as! WebPolicyDelegate
will fail.
self (ViewController) does not implement WebPolicyDelegate.
You need to do:
class ViewController: NSViewController, WebFrameLoadDelegate, WebPolicyDelegate {
and implement the delegate.
Also make sure that your webView
@IBOutlet weak var webView: WebView!)
is connected to your webView in your Interface Builder!
Upvotes: 1