Alright, this should not be too difficult, but Sunday morning proves me wrong...
I have an Array with structs, and want to remove only one struct that matches its name property to a String. For example:
struct Person {
let name: String
}
var myPersons =
[Person(name: "Jim"),
Person(name: "Bob"),
Person(name: "Julie"),
Person(name: "Bob")]
func removePersonsWith(name: String) {
myPersons = myPersons.filter { $0.name != name }
}
removePersonsWith(name: "Bob")
print(myPersons)
results in:
[Person(name: "Jim"), Person(name: "Julie")]
But how do I only remove one Bob?
Personis just an example. I could have used a different example, eg balls with different colors, and then remove one red ball. Or fish in a river, and catch (remove) one salmon, etc.