Reputation: 12423
I have plist which contains array of dictionaries.
Each dictionary has several columns.
I would like to access the each data of dictionary wito for loop.
var qplist = NSArray(contentsOfFile: path)
// qplist is array of dictionary
for meta in qplist! { //Type 'Any' does not conform to protocol 'Sequence'
//meta['test']
}
How can I loop the array of dictionary??
I guess something like this ,,,, but its doesnt work.
for var meta:Dictionary in qplist! {
Upvotes: 1
Views: 856
Reputation: 2427
This is how you need to do it:
if let qplist = NSArray(contentsOfFile: path) as? [[String : Any]]{
for meta in qplist {
//meta['test']
}
}
Upvotes: 2
Reputation: 72410
Try like this way.
if let qplist = NSArray(contentsOfFile: path),
let array = qplist.objectEnumerator().allObjects as? [[String:Any]] {
for dictionary in array {
print(dictionary["test"])
}
}
Upvotes: 4