Problems with Array conversion in Swift 3

0

With the update of swift3 I'm getting the following error "type 'Any' has no subscript members", I've seen lots of questions about it and tested most of them but to no avail. The code where I'm having this error is as follows:

 Alamofire.request(mutableURLRequest)
                .responseJSON{
                    response in
                    if let value: AnyObject = response.result.value as AnyObject? {

                        let json = JSON(value)
                        for (index, subJson) in json {
                            self.addressArray.add(subJson.object)
                            let ind: Int = Int(index)!

                            let defaultvalue: Int = self.Array[ind]["IsDefault"] as? Int

                            if(defaultvalue == 1)
                            {
                                let prefs: UserDefaults = UserDefaults.standard
                                let ID: Int = self.Array[ind]["ID"] as! Int
                                let Name: String = self.Array[ind]["Tag"] as! String

                                prefs.set(addressName, forKey: "Name")
                                prefs.set(addressID, forKey: “ID")
                                prefs.synchronize()
                            }

                        }
                        self.listAddress.reloadData()
                    }
            }

Being that the error is everywhere I go in doing something like this self.Array[ind]["IsDefault"] as? Int .

    
asked by anonymous 18.10.2016 / 18:05

1 answer

0

Switch:

let json = JSON(value)

By:

let json = JSON(value) as! [String:AnyObject]

You have to cast JSON for the types you will handle in the code.

    
23.10.2016 / 03:38