给我一个示例和解释"循环array<Dictionary<String,String>>使用swift ...
这是一个显示2个循环的示例.第一个循环通过数组挑出每个字典.第二个循环遍历字典,挑出每个键,值对:
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)")
}
}
Run Code Online (Sandbox Code Playgroud)
这输出:
first: Fred
last: Jones
first: Joe
last: Smith
Run Code Online (Sandbox Code Playgroud)
请注意,字典是无序的,因此也可以打印:
last: Jones
first: Fred
last: Smith
first: Joe
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7319 次 |
| 最近记录: |