Reputation: 1868
I have the following plist file in my Swift iOS project. I want to read the keys without specifically mention and get the value for all the keys. I want to write this in Swift code. I tried the below code and getting all the keys and values. But, I want to check for each key(not mentioned specifically like "1234" etc.) and get the value for it. Please help how to achieve this?
var myDict: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource("UserDetails", ofType: "plist") {
myDict = NSDictionary(contentsOfFile: path)
NSLog("myDict: %@", myDict!)
}
Upvotes: 1
Views: 455
Reputation: 70098
You can use a tuple to loop in a dictionary:
for (key, value) in myDict! {
println("Key is \(key) and value is \(value)")
}
Upvotes: 1
Reputation: 36313
Just use this code
for (key, val) in myDict! {
println("\(key):\(val)")
}
to print the single keys/values.
Upvotes: 1