Created
March 20, 2017 09:50
-
-
Save leoiphonedev/310e6c193a41a2e26f9197b6f490ec07 to your computer and use it in GitHub Desktop.
Search function that will search data fom array as per user textinput
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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