My problem is pretty simple:
- I have a lot of user scores in my DataBase (I'm using Firebase by the way)
- I would like to get these scores (it's easy) and sort them (less easy)
If the user finish the workout, he will enter his time, if not, he will enter the number or repetitions.
To be simple, the result object is like that:
Result |_ resultValue (Int) // It can be time in seconds or number of reps |_ isFinished (Int) // It can be 0 (not finished) or 1 (finished)
I would like to sort my results array like that:
- First: All results with isFinished == 1 are higher than the others
- Then: Sort results where isFinished == 1 by resultValue DESC
- Finally: Sort results where isFinished == 0 by resultValue ASC
I tried something like that:
self.results = self.results.sorted {
($0.result.isForTimeFinished!, $0.result.resultValue!) >
($1.result.isForTimeFinished!, $1.result.resultValue!)
}
So results of workout not finished are after results of workout finished, but "Sort results where isFinished == 1 by resultValue DESC" is not okay...
Do you know how I could combine all that?