I want to filter an array of objects.
struct Person {
let name: String
}
let p1 = Person(name:"test1")
let p2 = Person(name:"test1")
let p3 = Person(name:"test2")
let persons = [p1, p2, p3]
How i can filter the persons list and return the persons which have the same name?
I have tried to use a filter method, but I can't apply it with multiple arguments.
I am looking for a functional solution like a filter or a reduce function and not looping over the list.
I have tried to use a filter method, but I can't apply it with multiple arguments.?filter the persons list and return the persons which have the same name? With this example input[Person(name:"test1"), Person(name:"test2")]what result do you expect?groupBycomparison and an example "before" and "after operation" state). In it's current form it just seems as iflet personsWithTest1Name = persons.filter { $0.name == "test1" }would do the trick, but judging from the answers below (and your feedback to them( this is not what you wish for.