在我的应用程序中,我使用了这段代码,它运行得很好:
var data3: NSArray = [] //1
for gg in data3{ //2
var hh:String = gg["percentage"] as String //3
perchomerec = hh.toInt()! //4
}
现在我更新了我的 xCode
和 OSx
版本,现在这段代码给出了这个错误(在//3 行):
[SKNode] is not convertible to String
我需要更改什么?
最佳答案
从 Swift 1.2 开始,as
运算符只能用于向上转型。向下转型时,您应该使用 as!
或 as?
(详细说明可以在例如 The Swift Programming Language 中找到)。
var hh:String = gg["percentage"] as! String
关于ios - (SKNode) 无法转换为字符串(它正在使用旧的 xCode),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30597083/