swift - 迁移到 Swift 2 时出现错误 "Ambiguous use of subscript"

标签 swift swift2

我刚刚将代码从 swift 1.2 迁移到 Swift 2,但遇到了错误:

Ambiguous use of subscript

上线

if((value["Success"] as! Int) == 1)

func selectorGetUpdateBuyer(notification:NSNotification)
    {
    if(self==notification.object as! BackProfilController)
        {
            NSNotificationCenter.defaultCenter().removeObserver(self,name:PixoNotificationCenter.PNC.AppixiaExchanges_to_FrontProfilController_getUpdateBuyer,object:nil)
            var succes:Bool=false
            for(key,value) in notification.userInfo as NSDictionary!
            {
                if(key as! String=="Result")
                {
                    if((value["Success"] as! Int) == 1)
                    {
                        succes=true
                    }
                }
        }
    }

有人知道我应该纠正什么以避免这个错误吗?

最佳答案

编译器不知道的类型。

您可以使用:

if(key as! String=="Result")
{
    if(((value as! NSDictionary)["Success"] as! Int) == 1)
    {
        succes=true
    }
}

关于swift - 迁移到 Swift 2 时出现错误 "Ambiguous use of subscript",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34375237/

相关文章:

swift - 如何在 Swift 中为泛型类创建单例

ios - iOS-Swift。从MVC到MVVM重构。使用Delegate方法处理IBAction

swift - AVCaptureVideoDataOutput 中的无效键 -> ProfileLevel (macOS)

swift - Swift 中获取数组的 Element 类型(通过反射)

Swift POST 请求不起作用

ios - NSFileManager.defaultManager().createFileAtPath() 返回 false

swift - 在应用程序中按退出键时发出 "funk"声音

ios - 如何获取待处理的UNNotificationRequest的剩余时间?

c - swift3.0 无法将类型 '[UnsafeMutablePointer<Int8>]' 的值转换为预期的参数类型 'UnsafeMutablePointer<Int8>?'

swift - 有什么理由不在 Swift 中使用单例 "variable"?