Type nsfastenumerationiterator.element aka any of them have no members

I upgraded Xcode from 7 to 8 and Swift from 2.3 to 3.

I get this error in let names = candidate["CandidateName"]! :

type nsfastenumerationiterator.element aka any any has no substring elements

enter image description here

  let url = URL(string: "https://website.com") let data = try? Data(contentsOf: url!) var tmpValues = try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSArray tmpValues = tmpValues.reversed() as NSArray reloadInputViews() for candidate in tmpValues { if ((candidate as? NSDictionary) != nil) { let names = candidate["CandidateName"]! //self.values.append(candidate["CandidateName"]) self.values.append(name!) print(name) } } 
+6
source share
1 answer

I think your for loop should be nice in this case. This is a job for me. But make sure var tmpValues.

 for candidate in (tmpValues as? [[String:Any]])! { if ((candidate as? NSDictionary) != nil) { let names = candidate["CandidateName"]! as? String //self.values.append(candidate["CandidateName"]) self.values.append(name!) print(name) } } 
+9
source

All Articles