4

I have a ViewController that looks something like:

import UIKit
import WebKit

class ViewController: UIViewController {
    @IBOutlet var webView: WKWebView!
}

In my storyboard I have a WKWebView as a subview of my main view. I've linked up the IBOutlet but when I run the application I receive:

EXC_BAD_ACCESS (code=1, address=0x431)

enter image description here enter image description here

What am I doing wrong here and how do I fix it?

Kyle Decot
  • 20,715
  • 39
  • 142
  • 263

2 Answers2

7

WKWebView is not supported on Storyboards. You have to create it by code. The web view element you are using in your Storyboard is a UIWebView.

Ruben Marin
  • 1,639
  • 14
  • 24
0

Use this simple and direct code to create and load your WKWebView:

        let webView = WKWebView(frame:NSMakeRect(0, 0,1000, 1000))
        webView.load(NSURLRequest(url:NSURL(string:"https://YourWebURLToLoad") as! URL) as URLRequest)
        webView.navigationDelegate = self;
        self.window.contentView?.addSubview(webView)
Jeba Moses
  • 809
  • 8
  • 25