我刚刚将代码从 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/