I actually tried to add if-else statement in the showPage func, but it doesn't work correctly.
func openPage(action : UIAlertAction){
if let url = URL(string: "http://" + action.title!) {
webView.load(URLRequest(url: url))
}else{
let ac = UIAlertController(title: "Valid URL", message: "wrong url", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "Close", style: .cancel))
present(ac , animated: true)
}
}
There are some syntax errors in your code.
let url = URL(string: "http://" + action.title!);
if (URL) {
//do something...
}
let url = new URL(string: "http://" + action.title!);
function openPage(action: UIAlertAction) {
try {
//do something...
} catch (e) {
//handle error...
}
}