Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leoiphonedev/310e6c193a41a2e26f9197b6f490ec07 to your computer and use it in GitHub Desktop.
Save leoiphonedev/310e6c193a41a2e26f9197b6f490ec07 to your computer and use it in GitHub Desktop.
Search function that will search data fom array as per user textinput
func searchRecordsAsPerText(_ textfield:UITextField) {
searchedArray.removeAll()
if textfield.text?.characters.count != 0 {
for strCountry in countriesArray {
let range = strCountry.lowercased().range(of: textfield.text!, options: .caseInsensitive, range: nil, locale: nil)
if range != nil {
searchedArray.append(strCountry)
}
}
} else {
searchedArray = countriesArray
}
tblCountries.reloadData()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment