I am a newbie and I have a new project. I am trying to execute a search function. I have a set of dictionaries containing firstName and lastName as keys, I need to filter people based on firstName, which contains a search string
let nameList : [Dictionary<String,String>] =
[["firstName" : "John Sam","lastName" : "Smith"],
["firstName" : "Johnny","lastName" : "Smith"],
["firstName" : "Albert","lastName" : "Smith"],
["firstName" : "Alby","lastName" : "Wright"],
["firstName" : "Smith","lastName" : "Green"]]
Like in lens C, I could easily do with
[NSPredicate predicatewithformat:"firstName contains[c] %@",searchText]
I also understand that the same predicate can be done on Swift. but I'm looking for the Swift equivalent, so that I can get how to use the map and filter. Any help appreciated
source
share