Swift链接命令

时间:2014-10-09 20:15:58

标签: swift casting chaining

我正试图用swift链接一些带有强制转换的命令。有谁知道为什么会发生以下情况变量赋值部分工作正常,但如果我尝试将它们链接在一起,则会产生似乎无法修复的编译错误。

var tempArr = JSONDict["years"]! as [AnyObject]
var tempDict = tempArr[0] as Dictionary<String,AnyObject>
var tempString = tempDict["year"]! as String
var tempInt = tempString.toInt()
var year = (((JSONDict["years"]! as [AnyObject])[0] as Dictionary<String,AnyObject>)["year"] as String).toInt()

提前致谢!

1 个答案:

答案 0 :(得分:0)

!

之后,您遗失了["year"]
 var year = (((JSONDict["years"]! as [AnyObject])[0] as Dictionary<String,AnyObject>)["year"]! as String).toInt()