gpt4 book ai didi

ios - 无法将类型 'NSMutableArray' 的值转换为预期的参数类型 '[SKTexture]'

转载 作者:行者123 更新时间:2023-11-28 11:06:54 24 4
gpt4 key购买 nike

我收到以下代码的错误:

func prepareAnimationForDictionary(settings: NSDictionary,repeated: Bool) -> SKAction {
let atlas: SKTextureAtlas =
SKTextureAtlas(named: settings["AtlasFileName"] as! String)
let textureNames:NSArray = settings["Frames"] as! NSArray
let texturePack: NSMutableArray = []

for texPath in textureNames {
texturePack.addObject(atlas.textureNamed(texPath as! String))
}

let timePerFrame: NSTimeInterval = Double(1.0/(settings["FPS"]
as! Float))

let anim:SKAction = SKAction.animateWithTextures(texturePack,
timePerFrame: timePerFrame) // the error I get is here
if repeated {
return SKAction.repeatActionForever(anim)
}else{
return anim
}

最佳答案

只需使用预期的(Swift)类型

...
let textureNames = settings["Frames"] as! [String]
var texturePack = [SKTexture]()

for texPath in textureNames {
texturePack.append(atlas.textureNamed(texPath))
}
...

从 Swift 的角度来看,可变的 Foundation 集合类型 NSMutableArrayNSMutableDictionary 是类型未指定的,并且与 Swift native 对应类型无关。

关于ios - 无法将类型 'NSMutableArray' 的值转换为预期的参数类型 '[SKTexture]',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37056579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com