Give me one Example and explanation for "loop through array<Dictionary<String,String>>
using swift...
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)")
}
}
This outputs:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With