L'erreur "Utilisation ambiguë de 'indice'" est en cours lorsque vous ne construisez que sur un vrai iPhone. Ne pas avoir de problèmes lors de l'utilisation du simulateur. Voici mon code:Utilisation ambiguë de 'indice' Erreur de compilation Swift 3
let url=URL(string:myUrl)
do {
let allContactsData = try Data(contentsOf: url!)
let allContacts = try JSONSerialization.jsonObject(with: allContactsData, options: JSONSerialization.ReadingOptions.allowFragments) as! [String : AnyObject]
if let arrJSON = allContacts["data"] {
for index in 0...arrJSON.count-1 {
let aObject = arrJSON[index] as! [String : AnyObject]
if(ChooseSubject.mineFagKoder.contains(aObject["subject"] as! String)){
ids.append(aObject["id"] as! String)
names.append(aObject["name"] as! String)
subjects.append(aObject["subject"] as! String)
descriptions.append(aObject["description"] as! String)
deadlines.append(aObject["deadline"] as! String)
}
}
}
Je pense que le problème peut venir de [String: AnyObject]. Je ne suis pas un expert de Swift, mais en lisant j'ai eu quelques informations sur des scénarios similaires. Vérifiez cela http://stackoverflow.com/questions/33642059/ambiguous-use-of-subscript-in-swift ou même http://stackoverflow.com/questions/33592699/ambiguous-use-of-subscript-xcode- 7-1 – Balanced
Quelle ligne exactement? 'Let aObject = arrJSON [index] as! [String: AnyObject] 'J'imagine que c'est parce que vous n'avez pas dit au compilateur que' arrJSON' est un tableau, donc vous ne pouvez pas faire 'arrJSON [index]'. – Larme
Cette ligne: let aObject = arrJSON [index] as! [String: AnyObject]. Comment puis-je savoir que arrJSON est un tableau? –