I want to know who have "choix1" in this array.
var arrayVote = ["James: choix1, Julien: choix2, Paul: choix1, Teddy; choix1"]
And i want for result: An array with the name of personnes who have "choix1"
Like that : [James, Paul, Teddy]
I want to know who have "choix1" in this array.
var arrayVote = ["James: choix1, Julien: choix2, Paul: choix1, Teddy; choix1"]
And i want for result: An array with the name of personnes who have "choix1"
Like that : [James, Paul, Teddy]
I think you should create [NSDictionary]
instead on [String]
and do like so:
var arrayVote = ["James": "choix1", "Julien": "choix2", "Paul": "choix1", "Teddy": "choix1"]
var result: [String] = []
arrayVote.forEach {
if $1 == "choix1" {
result.append($0)
}
}
print(result) // ["Paul", "Teddy", "James"]