I am trying to do this but it's says
Value of type 'AnyObject?' has no member 'Generator'
So this is my code.
let dataDictionary:NSDictionary = try NSJSONSerialization.JSONObjectWithData(responseObject as! NSData, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
var customerArray = dataDictionary.valueForKey("kart")
for js: NSDictionary in customerArray {
let nameArray: NSArray = js.valueForKey("name")
}
What I am doing wrong.I didn't figure out.Thank you for your helps.
Your customerArray
is an Optional, it has the type AnyObject?
(this is because .valueForKey
returns an Optional). You can't loop over an Optional. Solution is to cast the result as an array while safe unwrapping:
if let customerArray = dataDictionary.valueForKey("kart") as? NSArray {
for js in customerArray {
let nameArray = js.valueForKey("name")
// ...
}
}
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