Trying to sort an NSMutableDictionary in Swift 3, code from Swift 2 doesn't work for me anymore (various errors).
I am trying to use the following code to sort my dictionary by its values, which are floats:
var sortedDict = unsortedDict.allValues.sorted({ $0 < $1 }).flatMap({ floatedlotterydictionary[$0] })
Essentially, I want this unsorted dictionary...
{
a = "1.7";
b = "0.08";
c = "1.4";
}
...to turn into this sorted dictionary...
{
b = "0.08";
c = "1.4";
a = "1.7";
}
But using that line of code from above returns the error "argument type anyobject does not conform with type NSCopying" for the $0 < $1
part. So how can I sort a dictionary by its values in Swift 3?
(Note: That line of code came in part from this answer.)
I am using Swift 3 in Xcode 8 beta 1.
NSMutableDictionary
in Swift. It is not related to the SwiftDictionary
at all. – vadian