I have an array that has integers as keys, and strings for values
var dictionary = [Int: String]()
All of these try's either end in compile error for Swift 5:
dictionary = dictionary.keys.sorted()
dictionary = (dictionary.sorted{ $0.key < $1.key })
dictionary = dictionary.sorted { $0.0 < $1.0 } .map { $0.1 }
reverseSortedValues = dictionary.sorted { $0.0 > $1.0 } .map { $0.1 }
dictionary = profileImagesDictionary.sorted(by: { $0.0.compare($1.0) == .OrderedAscending })
dictionary = profileImagesDictionary.sorted { $0.key
Code:
profileImagesDictionary = [Int : String](uniqueKeysWithValues: profileImagesDictionary.sorted{ $0.key > $1.key})
Console Output printed keys
before: dictionary = [3, 1, 2, 4, 0]
after: dictionary = [3, 0, 2, 1, 4]
I need it to rearrange the dictionary / actually sort it by keys.
So like instead of:
dictionary = [1: "a", 3: "c", 2: "b"]
It after being sorted would be:
dictionary = [1: "a", 2: "b", 3: "c"]