UIWebView crashing when loading URL
<p>This should be really straightforward but I have no idea why this code is not working. I try to load a basic URL into a <code>UIWebView</code> like this: </p>

<pre><code>    let string = "www.google.com".stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
    let url = NSURL(string: string!)

    if let ur = url {
        let request = NSURLRequest(URL: ur)
        webView.loadRequest(request)
    }
</code></pre>

<p>However each time I get this error: </p>

<p><strong>fatal error: unexpectedly found nil while unwrapping an Optional value</strong></p>

<p>Stepping through it nothing is <code>nil</code>. Figured I'd do this just to make sure: </p>

<pre><code>    let string = "www.google.com".stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())

    // unwrap the string
    if let str = string {

        let url = NSURL(string: str)

        // unwrap the url
        if let ur = url {
            let request = NSURLRequest(URL: ur)
            webView.loadRequest(request)
        }
    }
</code></pre>

<p>Which I still get the same crash! If I look at the thread I get this when running on a device: </p>

<blockquote>
  <p>0x656d6c &lt;+68>:  bl     0x6abac4                  ; function signature
  specialization 1 = Exploded> of
  Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString,
  Swift.StaticString, Swift.UInt) -> ()).(closure #2)</p>
</blockquote>

<hr>

<p>So my <code>UIWebView</code> is <code>nil</code> somehow...I have everything hooked up correctly? Any ideas
<a href="https://i.stack.imgur.com/nOODv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nOODv.png" alt="enter image description here"></a></p>