排序字典Swift 3.0



在某个编码时,我需要对字典进行排序以根据字典的键获取订购的数据。

我试图通过:

获得结果
let sortedDict = dict.sorted { $0.key < $1.key }

它导致:

let dict = ["a0":1, "a3":2 , "a10":2, "a20":3]

不过,所需的结果:

let dict = ["a0":1, "a10":2, "a20":3, "a3":2]

任何建议都将不胜感激。

预先感谢。

尝试以下:

    for i in 0..<parameters!.count {
        let key = "q(i)"
        if httpBody.contains(key){
            let regex = try! NSRegularExpression(pattern: "\b(key)\b", options: .caseInsensitive)
            httpBody = regex.stringByReplacingMatches(in: httpBody, options: [], range: NSRange(0..<httpBody.utf16.count), withTemplate: "q")
        }
    }

简单的排序功能在这里无法使用。

字典是一个无序的数据集,因此您无法创建有序的字典。

最新更新