Skip to main content

Can I make this Dictionary sort (smallest to biggest) algorithm more concise? Swift

I have the below sorting algorithm which takes an array of dictionary values as declared below:

guard var imageUrlString = anyImage.value as? [String:AnyObject] else { return }

I then loop through it adding the values with the smallest Int key to a new array to be used afterward. Thus the values in this array of AnyObjects would go from 1 to n.

I was wondering if I could make it more concise.

var values = [AnyObject]()
var keys = [String]()
var Done = false
var j = 1

 while !Done {
    for i in imageUrlString {
        let key = Int(String(i.key.last!))
        
        if j == key {
            values.append(i.value)
            keys.append(i.key)
            print(i, " This is the i for in if ")
            if imageUrlString.count == j {
                print("Done yet: yes", values[0], " ", values[3])
                Done = true
                break;
            }
            j+=1
        } else {
            print("No,,.")
        }
    }
}