0

As a followup to this question, I need to iterate over each .sks file in a folder, namely, "Levels".

My project looks like this:

My project

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").

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
michaelsnowden
  • 6,031
  • 2
  • 38
  • 83
  • 1
    Levels is a group (yellow icon), if you make it a folder reference (blue icon) Xcode will add it as a folder to the bundle. Files in groups will be added to the bundle root. But in this case it suffices to assume that level sks files simply have the "Level" prefix. – CodeSmile Sep 07 '14 at 21:49
  • @LearnCocos2D God that explains so much. I made it a blue folder and now it works as I would have hoped. Thanks! – michaelsnowden Sep 07 '14 at 22:14

0 Answers0