Search code examples
iosswiftswift3swift-dictionary

Type 'NSFastEnumerationIterator.Element' (aka 'Any') has no subscript members


I've found an exact solution for above error here http://stackoverflow.com/q/39429342/5309431 and I try to execute that in my code. But the issue is not solved. I don't know what I've made wrong. Please Help

for dict in self.levelRefArr{
  if let datas = dict["data"] as? [[String:Any]] { //Type 'NSFastEnumerationIterator.Element' (aka 'Any') has no subscript members
      print(datas)
   }                   
 }

Solution

  • levelrpfarr is most likely Any, you need to cast it to the actual type which tells the compiler the type of the items in the array

    for dict in self.levelRefArr as! [[String:Any]] { ...