Add http:// to NSURL if it's not there
NSString *urlString = @"google.com";
NSURL *webpageUrl;
if ([urlString hasPrefix:@"http://"] || [urlString hasPrefix:@"https://"]) {
webpageUrl = [NSURL URLWithString:urlString];
} else {
webpageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", urlString]];
}
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:webpageUrl];
[self.myWebView loadRequest:urlRequest];
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)
}