Swift 5:
class YourClass: UIViewController, UITextFieldDelegate {
// will trigger when return button from keyboard is pressed
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
performAction(textField)
return true
}
private func preformAction(_ textField:UITextField){
//... code here ...
}
}