swift – 类型nsfastenumerationiterator.element又名任何没有下标成员

前端之家收集整理的这篇文章主要介绍了swift – 类型nsfastenumerationiterator.element又名任何没有下标成员前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_0@ 我已经将 Xcode从7更新为8,将 Swift从2.3更新为3.

我在让名字=候选人[“候选人姓名”]时得到这个错误!:

type nsfastenumerationiterator.element aka any has no subscript members

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)

        }
    }
我认为你的循环应该是这样的.这对我有用.但请确保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)

     }
 }
原文链接:https://www.f2er.com/swift/318635.html

猜你在找的Swift相关文章