问题
As a followup to this question, I need to iterate over each .sks file in a folder, namely, "Levels".
My project looks like this:
Here's what I've written:
let directory = NSFileManager.defaultManager().currentDirectoryPath
let paths = NSBundle.mainBundle().pathsForResourcesOfType("sks", inDirectory: directory)
let files = paths.map() { (path : AnyObject) -> String in
return (path as String).lastPathComponent
}
println("Files\n\(files)")
let firstLevel = files[0]
if let scene = SKScene.unarchiveFromFile(firstLevel) {
// Never reached because firstLevel is AParticleFile
}
With the output:
"[AParticleFile.sks, Level1.sks, Level2.sks]"
The problem is that AParticleFile.sks
is a SpriteKit particle system, not an SKScene. It doesn't exist in the "Levels" directory, but I don't know how to get only the files in the "Levels" directory. What I've tried is directory.stringByAppendingPathComponent("Levels")
.
来源:https://stackoverflow.com/questions/25713326/get-a-list-of-all-spritekit-scenes-in-app-bundle