-4

The following is the action onclick a button to initiate webview and load the given URL. Working on Swift 3 Xcode 8 iOS 10.2

@IBAction func initWebView(_ sender: UIButton)
{
    if let webViewURL = URL(string: "somelink") {
        let webViewURLRequest = URLRequest(url: webViewURL)
        myWebView.loadRequest(webViewURLRequest)
    }
}

After running it gives the following error "fatal error: unexpectedly found nil while unwrapping an Optional value"

Can someone please help me. Thanks

  • Compare with this one http://stackoverflow.com/a/42001537/6433023 – Nirav D Feb 11 '17 at 04:11
  • @NiravD tried that already. gave error "missing argument for parameter 'mimeType' in call". Tried to fix that too. same results – Atharva Dandekar Feb 11 '17 at 04:21
  • 1
    It seems likely that `myWebView` is `nil`. Have you linked the outlet in your scene? – Paulw11 Feb 11 '17 at 04:21
  • @Paulw11 yes checked that again and again. – Atharva Dandekar Feb 11 '17 at 04:25
  • How have you created this view controller instance? Set an exception breakpoint. Use the debugger to see what is nil. – Paulw11 Feb 11 '17 at 04:26
  • Ok. Let's approach this logically. So far, you've researched some "unexpectedly found nil" questions and none fit - again so far. Which line of code is giving you this error? Have you set breakpoints? If so, what did they show you? Please, in order for us to help you we need a bit more info. –  Feb 11 '17 at 04:41
  • @dfd the error I'm getting is on the line `myWebView.loadRequest(webViewURLRequest)` Even the url which I'm building is getting displayed in console and its clean. – Atharva Dandekar Feb 11 '17 at 06:30
  • After lots of debugging I came to know that the request was not getting loaded by webview. So had to scrap the code and create new outlets and added a missing statement `myWebView.delegate = self` which solved the issue. Thank you all for quick help. – Atharva Dandekar Feb 12 '17 at 02:21

1 Answers1

0

check your URL.it might be nil