Alternatively, you can iterate with
if( [v respondsToSelector:@selector(isFirstResponder)] && [v isFirstResponder]) { [v resignFirstResponder]; break; }
This method will only call resignFirstResponder for the current first responder and stop when the current first responder is found. It will work with UITextFields, UITextViews, etc., as well as with any future text editing options (provided that they continue to implement response methods).
For a more general case, you can use
if( [v isKindOfClass:UITextField.class] ) { [v resignFirstResponder]; }
For general keyboard failure, preference is given to the first, since all that interests you is the keyboard. The object claims that it will process the message (method call), so you do not really need to care about what type it is. If you really need to make sure this is a UITextField, the second option is preferable.
source share