I\'m using the UISearchBar (but not the SearchDisplayController that\'s typically used in conjunction) and I\'d like to dismiss the keyboard when you hit the \'X\' button.>
Updated for SWIFT 3:
Suppose that the user has entered a string in searchfield and clicks x the following code works to hide keyboard when x is pressed
`
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)
{
if searchBar.text == nil || searchBar.text == ""
{
searchBar.perform(#selector(self.resignFirstResponder), with: nil, afterDelay: 0.1)
}
}
`