本文介绍了如何循环遍历 Array<Dictionary<String,String>>使用 Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给我一个例子和解释循环遍历array>
using swift...
Give me one Example and explanation for "loop through array<Dictionary<String,String>>
using swift...
推荐答案
这是一个显示 2 个循环的示例.第一个循环遍历数组,挑选出每个字典.第二个循环遍历字典,挑选出每个键值对:
Here is an example that shows 2 loops. The first loops through the array picking out each dictionary. The second loop loops through the dictionary picking out each key, value pair:
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
注意字典是无序,所以这也可以打印:
Note that dictionaries are unordered, so this could also print:
last: Jones
first: Fred
last: Smith
first: Joe
这篇关于如何循环遍历 Array<Dictionary<String,String>>使用 Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!