Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 3 JSON NSFastEnumerationIterator has no subscript members

Tags:

ios

swift

Im using Swift 3 and Alamofire 4.0. I am able to print out the entire response but I am having trouble looping through and printing out each value. I am getting a " Type 'NSFastEnumerationIterator.Element' (aka 'Any') has no subscript members when I try to print out 'title' below. Any help is greatly appreciated.

 Alamofire.request(url).responseJSON { response in
         if let dict = response.result.value as? Dictionary<String, AnyObject> {
            if let datas = dict["data"] as? NSArray{
                for data in datas{
                    print("DEVELOPER: \(data)")
                        if let title = data["myTitle"] as? String{
                            print(title)
                        }

                }
            }
        }
    } 
like image 503
kelsheikh Avatar asked Sep 10 '16 18:09

kelsheikh


Video Answer


1 Answers

Sometimes you wanna keep your data as structured, all you have to do is check for the dictionary itself while in loop like the following:

for apple in apples { 
 if let _ = apple as? [String:AnyObject] {
// do whatever you like here
   }
 }
like image 127
Giggs Avatar answered Nov 11 '22 20:11

Giggs