How to hide the keyboard programmatically in iphone?
It's easy:
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
UIApplication.shared.keyWindow?.endEditing(true)
take a look at UIView Class Reference for endEditing. Causes the view (or one of its embedded text fields) to resign the first responder status. And keyWindow is the only window that receives keyboard events, so this solution is guarantied to always work.