-1

I have declared the following variable:

var Results = [String : Int]()

Now i want to order this Array from small to Big, based on the Integer values.

I have tried this, but it is only working for the String values:

func getSmallestResult(fingerprintingResult:[String:Int]) {

    var closestObservationPoint:String = String()

    var myArr = Array(fingerprintingResult.keys)
    var sortedKeys: () = sort(&myArr) {
        var obj1 = fingerprintingResult[$0] // get ob associated w/ key 1
        var obj2 = fingerprintingResult[$1] // get ob associated w/ key 2
        return obj1 < obj2
    }
JaredH
  • 2,338
  • 1
  • 30
  • 40
user3143691
  • 1,533
  • 3
  • 11
  • 19

1 Answers1

0

This is not a 2 dimensional array, but a Dictionary. Try this:

let sortedDictionary = sorted(Results) { $0.0 < $1.0 }
println(sortedDictionary) // [(A, [1, 2]), (D, [5, 6]), (Z, [3, 4])]
Reece Kenney
  • 2,734
  • 3
  • 24
  • 57