类型Any没有下标成员Swift 3.0 [英] Type Any has no subscript members Swift 3.0
本文介绍了类型Any没有下标成员Swift 3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试转换功能使其与Swift 3.0兼容.必须将参数json
从AnyObject
更改为Any
:
Trying to convert a function to make it Swift 3.0 compatible. Had to change the parameter json
from AnyObject
to 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没有下标成员" .我在这里做错什么了?
However at the line: let responseMessage = json["response"]! as? String
I am now getting the error: "Type Any has no subscript members". What am I doing wrong here?
推荐答案
在使用下标之前,您必须将Any强制转换为AnyObject.
You have to cast Any to AnyObject before using subscript.
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
}
这篇关于类型Any没有下标成员Swift 3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文