Reputation: 23
@IBAction func endEditingText(_ sender: Any) {
let baseURL = "http://api.openweathermap.org/data/2.5/forecast?q"
let APIKeysString = "&appid=14b92e1046c4b6e4f4d5adda8259131b"
guard let cityString = sender.text else {return}
if let finalURL = URL (string:baseURL + cityString + APIKeysString) {
requestWeatherDate(url: finalURL)
} else {
print("error")
}
}
Upvotes: 0
Views: 3122
Reputation: 61
You can type cast sender to UITextField.
@IBAction func endEditingText(_ sender: Any) {
let textFieldObject = sender as! UITextField
....
}
or at the time of creating IBAction you can use UITextField in place of Any.
@IBAction func endEditingText(_ sender: UITextField) {
....
}
Upvotes: 3
Reputation: 285064
The error is pretty clear. The sender
is declared as Any
so the compiler does not know the actual static type.
Change it to UITextField
:
@IBAction func endEditingText(_ sender: UITextField) { ...
Upvotes: 2