I am using web view in my app, getting a URL from a text field. It works if the string starts with \"http://\". I am trying to modify the code so that it can also handle the
Let me update answer to Swift 4 and WKWebKit
var urlString = "www.apple.com"
if urlString.hasPrefix("https://") || urlString.hasPrefix("http://"){
let myURL = URL(string: urlString)
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}else {
let correctedURL = "http://\(urlString)"
let myURL = URL(string: correctedURL)
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}