SWIFT: Why I can't get the current URL loaded in UIWebView?

2 Solutions Collect From Internet About “SWIFT: Why I can't get the current URL loaded in UIWebView?”

If you put parentheses around this, the error goes away:

let currentURL : NSString = (webView.request?.URL.absoluteString)!

Beware that yours might not be just a syntax problem.
If your webView is in a state where request == nil your app will crash at runtime.

I’d rather write something like:

if let currentURL = webView.request?.URL.absoluteString {

    // do things ...
    // Your currentURL will be automatically bridged to Swift's String type 

} else {

   // Just in case request is nil ...

}