尝试转换函数以使其与Swift 3.0兼容。必须将参数json
从AnyObject
更改为Any
:
fileprivate func checkForAuthorizationFailure(_ json: Any) -> Bool {
let responseMessage = json["response"]! as? String
if responseMessage == "Unauthorized. Invalid token or email." {
return true
}
return false
}
但是在第let responseMessage = json["response"]! as? String
行:我现在收到错误: “Type Any没有下标成员” 。我在这里做错了什么?
答案 0 :(得分:5)
在使用下标之前,必须将Any转换为AnyObject。
fileprivate func checkForAuthorizationFailure(_ json: Any) -> Bool {
let responseMessage = (json as AnyObject)["response"]! as? String
if responseMessage == "Unauthorized. Invalid token or email." {
return true
}
return false
}