FireUser
FireUser

Reputation: 183

Ambiguous use of subscript. Array Swift IOS

I try to compile on device but i get this error. Any help?. In the simulator works perfectly.

I get an ambiguous use of subscript error in the following code and was hoping somebody else has encountered this and know the fix.

 case .Success:
                if response.response?.statusCode == 200 {
                      print ("Respuesta 200")
                    if let value = response.result.value {

                        let respuestaJSON = JSON(value)
                        let objsonUSUARIOS = respuestaJSON["d"].object
                        let arrayUsuarios = objsonUSUARIOS["results"]!
                        //print ("Usuarios: ",String(arrayUsuarios))

                        for  i in 0 ..< arrayUsuarios!.count{
                            let boletines = boletinJSON()

                            if  let item = arrayUsuarios![i] as? [String: AnyObject]{
                                )

                                if let person = item["Title"] as? String
                                {
                                    boletines.name = person

                                }

                                if let person = item["Portada"] as? String
                                {
                                    boletines.imagen = person

                                }

                                if let person = item["Created"] as? String
                                {
                                    boletines.fecha = person
                                }

                                if let person = item["AttachmentFiles"] as? [String: AnyObject] {
                                    if let itemAttach = person["__deferred"] as? [String: AnyObject]{
                                        if let itemdeferred = itemAttach["uri"] as? String {
                                            boletines.urldescarga = itemdeferred
                                        }
                                    }
                                }

                                self.boletin.append(boletines)
                                self.view.hideToastActivity()

                            }

                        }



                    }
                      self.tableView.reloadData()

                    //  self.view.hideToastActivity()
                }

Upvotes: 0

Views: 370

Answers (2)

pkc
pkc

Reputation: 8516

Inform the compiler what the intermediary object objsonUSUARIOS is of type

let objsonUSUARIOS = respuestaJSON["d"].object

After the above statement, the compiler does not know what kind of object he is dealing with. So make sure that you can actually do all the casting as below

let objsonUSUARIOS = respuestaJSON["d"].object as! Dictionary
let arrayUsuarios = objsonUSUARIOS["results"]! as! Array

Upvotes: 3

Nirav D
Nirav D

Reputation: 72440

The problem is that you have not specified the type of object arrayUsuarios is Array, so try to explicit type cast the arrayUsuarios Array

let arrayUsuarios = objsonUSUARIOS["results"] as! [[String: AnyObject]]

Upvotes: 2

Related Questions