Any 类型没有下标成员 Swift 3.0

2024-04-02

尝试转换函数以使其兼容 Swift 3.0。必须更改参数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我现在收到错误:“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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Any 类型没有下标成员 Swift 3.0 的相关文章

随机推荐