I want to filter an array which contains an array of Strings.
My code is:
if(!(searchString?.isEmpty)!) {
shouldShowSearchResults = true
// Filter the data array and get only those countries that match the search text.
filteredPlazaDictionary = plazaDictionary.filter({ (match) -> Bool in
let matchText: NSString = match[1] as NSString
return (matchText.range(of: searchString!, options: NSString.CompareOptions.caseInsensitive).location) != NSNotFound
})
}
Here, filteredPlazaDictionary[[String]] and plazaDictionary[[String]] and I want to match every array[1] inside plazaDictionary with searchString. Help please.
(!(searchString?.isEmpty)!)do? It seems far too complicated.searchStringhappens to benil(foo?.bar)!is nonsense, to check for non-nil and non-empty useif let query = searchString, !query.isEmpty { ...(no parentheses at all).plazaDictionaryis a[[String]], then why is it calledplazaDictionary? It's an array, not a dictionary.