尝试转换函数以使其与 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"]!作为? String
我现在收到错误:“Type Any 没有下标成员”。我在这里做错了什么?
最佳答案
在使用下标之前,您必须将 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
}
关于ios - Type Any 没有下标成员 Swift 3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39641676/