I have an dictionary var dic = [TimeInterval: [CustomObject: Double]]()
TimeInterval
is a timestamp. CustomObject
is an object with property id
inside (of type String
). And AudioLevel
is a double.
I succeed to print object inside with:
for (key, values) in dic {
for value in values {
print("\(key): participant id : \(value.key.id) ... AudioLevel: \(value.value)")
}
}
It prints in my example :
1581361504.064956: participant id : id1 ... AudioLevel: 1.8426420022371925
1581361504.0642018: participant id : id2 ... AudioLevel: 0.0030890756301589217
1581361504.065456: participant id : id2 ... AudioLevel: 4.256374635644427
1581361504.061193: participant id : id1 ... AudioLevel: 1.744451095262131
Now I would like to have an dictionary that contains [CustomObject: Int]
where Int
is the rank of the participant. Here id2
will be first (4.256374635644427 + 0.0030890756301589217
> 1.744451095262131 + 1.8426420022371925)
Maybe I have to do a reduce based on id + sum
of audiolevel, and after to flatMap
to retrieve my CustomObject
?