I’m doing a searching task using UItextField and I tap search button it should begin async task fo calling web api and also dismiss the keyboard. But keyboard remains there. Here is the code
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
   attemptPost { (success) in
       DispatchQueue.main.async {
        spinner.stopAnimation(self)
        btnOk.isEnabled = true
        btnCancel.isEnabled = true
    }
     // after this keyboard should dismiss but does not do so
      return true
}
func attemptPost(_ completion:@escaping (Bool)->()) {
    // some code
}
I want keyboard to dismiss once we tap search button and async task should also start.
 
    