I need to get the current URL loaded into the webview and this is how I'm trying to get that but it gives me this error: "Cannot convert the exporessions type 'ST7??' to type 'String'
and this is the code
var currentURL : NSString = webView.request?.URL.absoluteString!
What is wrong with this?
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 ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With