type 'Any' has no subscript members

后端 未结 2 1871
时光说笑
时光说笑 2020-12-20 05:39
let employerName = snapshot.value! [\"employerName\"] as! String
let employerImage = snapshot.value! [\"employerImage\"] as! String
let uid = snapshot.value! [\"uid\         


        
2条回答
  •  难免孤独
    2020-12-20 06:06

    Since you want to treat snapshot.value as an unwrapped dictionary, try casting to one and, if it succeeds, use that dictionary.

    Consider something like:

    func findElements(candidate: Any) {
        if let dict: [String : String] = candidate as? Dictionary {
            print(dict["employerName"])
            print(dict["employerImage"])
            print(dict["uid"])
        }
    }
    
    // Fake call    
    let snapshotValue = ["employerName" : "name", "employerImage" : "image", "uid" : "345"]
    findElements(snapshotValue)
    

提交回复
热议问题