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



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

下标的使用不明确

在线

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
                    }
                }
        }
    }

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

编译器不知道value的类型。

您可以使用:

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

相关内容

最新更新