简体   繁体   English

下标使用模棱两可。 阵列Swift IOS

[英]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()
                }

Inform the compiler what the intermediary object objsonUSUARIOS is of type 通知编译器中间对象objsonUSUARIOS的类型

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

问题是您尚未指定对象arrayUsuarios的类型为Array ,所以请尝试显式类型arrayUsuarios Array

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM