如何循环Array <Dictionary <String,String>使用Swift
给我一个例子和解释“循环array<Dictionary<String,String>>
使用SWIFT …
这是一个显示2个循环的例子。 通过arrays的第一个循环挑出每个字典。 第二个循环遍历字典选取每个键,值对:
let people:Array<Dictionary<String,String>> = [["first":"Fred", "last":"Jones"], ["first":"Joe", "last":"Smith"]] // Grab each person dictionary from the array of dictionaries for person in people { // Grab each key, value pair from the person dictionary // and print it for (key,value) in person { println("\(key): \(value)") } }
这输出:
first: Fred last: Jones first: Joe last: Smith
请注意,字典是无序的 ,所以这也可以打印:
last: Jones first: Fred last: Smith first: Joe