I have an alert in my iOS app, with two buttons on the alert. I'd like to call a function I have, called searchTheWeb() when the user selects that option:
alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.default, handler: nil))
alert.addAction(UIAlertAction(title: "Search The Web!", style: UIAlertActionStyle.default, handler: nil))
func searchTheWeb(){
let word = self.userInfo.text! + self.faceResults.text! + self.labelResults.text!
if let encoded = word.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed), let url = URL(string: "https://www.google.com/#q=\(encoded)") {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
}
So in that addAction with the title Search The Web! How can I call that function?