-4

I need to sort the array values which are get from the dictionary . I need to sort it based on key or values .

i have tried the code

var Dictionary = [Int : String]()
Dictionary  = [1: "pandi" , 2 : "nashrin" , 3 :"vanji"]
print(Dictionary)

var dicarray = [[Int :String]]()
dicarray = [Dictionary]
print(dicarray)
let dictKeyInc = dicarray.sorted(by: <)
print(dictKeyInc)

but i was not able to sort .

Subramanian Mariappan
  • 3,736
  • 1
  • 14
  • 29
vengai
  • 3
  • 1
  • Are you want to sort it by keys value? – shraddha11 Feb 05 '20 at 07:17
  • want to sort the values in array in anyway – vengai Feb 05 '20 at 07:19
  • There is nothing to sort, your array contains only 1 element. If you have many dictionaries what do you want to sort by? – Joakim Danielson Feb 05 '20 at 07:21
  • Can you show the expected result for the dictionary `[1: "pandi" , 2 : "nashrin" , 3 :"vanji"]`? And ideally you should show more examples of expected inputs and outputs. – Sweeper Feb 05 '20 at 07:21
  • First of all need assign the values from dictionary to array . And the need to sort the elements in an array in any way . name of the array is assigned as "dicarray" – vengai Feb 05 '20 at 07:25

1 Answers1

-1

Please use this.

Dictionary.sorted { (obj1, obj2) -> Bool in
   return obj1.key < obj2.key
}
shraddha11
  • 783
  • 4
  • 17