Dictionary with Arrays iPad 2 vs iPad Air 2 的排序顺序。为什么颠倒了?

Sort order Dictionary with Arrays iPad 2 vs iPad Air 2. Why reversed?

我在 iPad Air 2 上的测试失败了,但它在 iPad 2 上运行,我无法弄清楚。

我开始了一个新项目,现在我可以看到不同之处了。

如果我用数组创建字典:

let test = ["header1":["test1"],"header2":["test2"]]
print(test)

iPad Air 2 的结果将是:

["header2": ["test2"], "header1": ["test1"]]

但是在 iPad 2 它将是:

["header1": ["test1"], "header2": ["test2"]]

为什么在 iPad Air 2 上反转了?

您不是在创建一个数组的数组,您是在创建一个字典([String: Array] 类型),键为 header1header2

字典未排序。

您创建了一个字典,键是 String 值是 Array<String>,

字典不是有序集合

如果你想要数据有序,你应该使用Array