This is because the valueForKey method returns an Optional value of AnyObject type ( AnyObject? ). Indeed, AnyObject does not have a Generator member and cannot be used in a for..in loop (as well as an Optional value). Thus, you must expand the optional value and apply it to the expected type, for example:
let dataDictionary:NSDictionary = try NSJSONSerialization.JSONObjectWithData(responseObject as! NSData, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary var customerArray = dataDictionary.valueForKey("kart")! as! [NSDictionary] for js: NSDictionary in customerArray { let nameArray = js.valueForKey("name") as! NSArray }
source share