SceneKit Swift3 编译器错误
SceneKit Swift3 compiler-error
我正在尝试 运行 在 SceneKit 中制作动画 "DAE" 模型:
let url = Bundle.main.url(forResource: "art.scnassets/Player(walking)", withExtension: "dae")
let sceneSource = SCNSceneSource(url: url!, options: [SCNSceneSource.LoadingOption.animationImportPolicy: SCNSceneSource.AnimationImportPolicy.playRepeatedly] )
let animationIds: NSArray = sceneSource?.identifiersOfEntries(withClass: CAAnimation)
for eachId in animationIds {
let animation: CAAnimation = (sceneSource?.entryWithIdentifier(eachId as! String, withClass: CAAnimation.self))!
animations.add(animation)
}
character?._walkAnimations = animations
但是编译器抛出就行了:
let animationIds: NSArray = sceneSource?.identifiersOfEntries(withClass: CAAnimation)
并写入错误:
无法转换“[String]”类型的值?指定类型 'NSArray'
请帮我解决这个问题。
提前致谢。
为什么要将 [String]?
转换为 NSArray
,然后再次将每个元素转换为 String
,不需要它,只需使用 Swift native Array
并用 if let
或 guard let
.
包装可选值
guard let animationIds = sceneSource?.identifiersOfEntries(withClass: CAAnimation) else {
return
}
for eachId in animationIds {
if let animation = sceneSource?.entryWithIdentifier(eachId, withClass: CAAnimation.self) {
animations.add(animation)
}
}
character?._walkAnimations = animations
我正在尝试 运行 在 SceneKit 中制作动画 "DAE" 模型:
let url = Bundle.main.url(forResource: "art.scnassets/Player(walking)", withExtension: "dae")
let sceneSource = SCNSceneSource(url: url!, options: [SCNSceneSource.LoadingOption.animationImportPolicy: SCNSceneSource.AnimationImportPolicy.playRepeatedly] )
let animationIds: NSArray = sceneSource?.identifiersOfEntries(withClass: CAAnimation)
for eachId in animationIds {
let animation: CAAnimation = (sceneSource?.entryWithIdentifier(eachId as! String, withClass: CAAnimation.self))!
animations.add(animation)
}
character?._walkAnimations = animations
但是编译器抛出就行了:
let animationIds: NSArray = sceneSource?.identifiersOfEntries(withClass: CAAnimation)
并写入错误:
无法转换“[String]”类型的值?指定类型 'NSArray'
请帮我解决这个问题。
提前致谢。
为什么要将 [String]?
转换为 NSArray
,然后再次将每个元素转换为 String
,不需要它,只需使用 Swift native Array
并用 if let
或 guard let
.
guard let animationIds = sceneSource?.identifiersOfEntries(withClass: CAAnimation) else {
return
}
for eachId in animationIds {
if let animation = sceneSource?.entryWithIdentifier(eachId, withClass: CAAnimation.self) {
animations.add(animation)
}
}
character?._walkAnimations = animations