If I have an array of strings, the formula is simple, it's something like:
let filteredArray = stringArray.filter({ $0.contains(filterWord)})
However, if I have an array of structures each with a property called "title", how do I filter and create an array of these structures with a keyword?
struct Item: Codable {
var title: String = ""
}
Thanks in advance.
CodePudding user response:
Since $0 is the current item you’re looking at just add the property you want to filter:
let filteredArray = stringArray.filter({ $0.title.contains(filterWord)})