数据在pList IOS Swift中是无序的

时间:2015-11-30 06:36:16

标签: ios swift plist

我正在创建一个应用程序,我通过获取Plist Dictionary来填充Array,并在表视图中显示。 一切都运转良好,但数据并不像我们用plist写的那样有序。

例外:

1-A

2-B

3-C

但是在运行时执行时,实际结果是这样的。

1-C

2-A

3-B

使用Swift并且无法在互联网上找到任何帮助,因为我真的不知道写些什么来寻求帮助。

因此,请尝试提供任何有用的信息以避免此问题。我可以按需提供代码。

编辑:

请检查此图像我的Plist结构 enter image description here

2 个答案:

答案 0 :(得分:0)

制作一个像这样的plist文件

enter image description here

然后获取数组并循环它

    let path = NSBundle.mainBundle().pathForResource("test", ofType:"plist")
    let array = NSArray(contentsOfFile: path!) as! [Dictionary<String, String>]

    for dic in array {
        let value = dic["someKey"]
    }

答案 1 :(得分:0)

如何对键进行排序并将值放入数组并使用它:

目标C:

let sortedKeysAndValues = sorted(dictionary) { $0.0 < $1.0 }

source

夫特:

190 million records

source