In swift, I am trying to make a text field that will allow a button to be enabled, but only when the text field contains an integer. How can I do this?
Swift 4: How about a simple guard and typecasting to Int as below
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
guard let _ = Int(string) else {
button.isEnabled = false
return true
}
button.isEnabled = true
return true
}