'swift nested dictionary sorted result error
the below source code results error like this:
"cannot assign value of type '[Dictionary<Int, Double>.Element]' (aka 'Array<(key: Int, value: Double)>') to type '[Int : Double]?' dateAndDict[date] = sortedDict"
Well, basically, what I am trying to do is sorting the nested Dictionary by Value.
source code:
let date = Date()
var dict = [2:4.0, 4:12.0 ,6:3.0,7:45.0, 8:15.0]
var dateAndDict:[Date:[Int:Double]]
let sortedDict = dict.sorted { currentElement , nextElement in
return currentElement.value < nextElement.value
}
dateAndDict[date] = sortedDict
thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
