ios - (SKNode) 无法转换为字符串(它正在使用旧的 xCode)

标签 ios xcode swift nsarray updates

在我的应用程序中,我使用了这段代码,它运行得很好:

var data3: NSArray = [] //1
for gg  in data3{ //2
    var hh:String = gg["percentage"] as String //3
    perchomerec = hh.toInt()! //4
}

现在我更新了我的 xCodeOSx 版本,现在这段代码给出了这个错误(在//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/

相关文章:

ios - 向 UIButton touchesBegan 添加声音的协议(protocol)

swift - 在 UserDefaults 中保存对象数组

Swiftui navigationLink macOS 默认/选中状态

ios - 使用 'case let x = y as NSString 发生内存泄漏

ios - NSUrlSession 在 Swift 中运行缓慢

ios - 尝试在我的应用程序中集成 Google 登录时找不到 "GoogleService-Info.plist"

ios - ObjC Plist 文件读取速度比 JSON 快?

ios - 删除导航栏下方的阴影线而不删除栏颜色?

ios - 何时在自定义 UIVIew 中添加 CAAnimation?

javascript - React Native 应用程序的 UI(在 iOS 上)滞后并且 fps 速率定期下降