I have the following dictionary and I would like to filter as follows
var emojiDict = [String: [[String]]]()
emojiDict = ["key one":[["item name 1", "item photo 1"],["item name 2", "item photo 2"], ["item name 3", "item photo 3"]],
"key two":[["item name 1", "item photo 1"],["item name 2", "item photo 2"], ["item name 3", "item photo 3"]],
"key three":[["item name 4", "item photo 1"],["item name 2", "item photo 2"], ["item name 3", "item photo 3"]]]
I would like to filter the above dictionary with search term item name 1 and return the following results
emojiDict = ["key one":[["item name 1", "item photo 1"]],
"key two":[["item name 1", "item photo 1"]]]
I tried below solution but it didn't work
let searchText = "item name 1"
let emojiDictFiltered = emojiDict.mapValues { $0.filter { $0.hasPrefix(searchText) } }.filter { !$0.value.isEmpty }
I kindly request for your assistance.