title: Swift: multiple sprite kit game scenes, loading in game scenes from view controller?
body: <p>Alright, so I have sprite kit game in Swift and I've created my game in the <code>GameScene.swift</code> file that apple sets up for you, and that all works great. Now I want to create another game scene within this same project.</p>
  
  <p>When the game is over, right now the game moves to a new UIViewController (named <code>GameOverBufferViewController</code>) that I've set up in the storyboard. But I want it to move to a completely new game scene. </p>
  
  <p>So I looked at how <code>GameViewController</code> loads in <code>GameScene.swift</code> (because the game scenes need a view controller as well as the <code>SKScene</code> code) and copied it into the view controller file for my UIViewController that the game moves to when it's game over. </p>
  
  <p>I changed the references to <code>GameScene</code> to match my new game scene swift file (<code>GameOverScene1</code>) and the <code>unarchiveFromFile</code> func to avoid an error:</p>
  
  <pre><code>import UIKit
  import SpriteKit
  
  extension SKNode {
      class func unarchiveFromFile2(file : NSString) -&gt; SKNode? {
          if let path = NSBundle.mainBundle().pathForResource(file as String, ofType: "sks") {
              var sceneData = NSData(contentsOfFile: path, options: .DataReadingMappedIfSafe, error: nil)
              var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData!)
  
              archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
              let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameOverScene1
              archiver.finishDecoding()
              return scene
          } else {
              return nil
          }
      }
  }
  
  
  class GameOverBufferViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // Do any additional setup after loading the view.
          if let scene = GameOverScene1.unarchiveFromFile2("GameOverScene1") as? GameOverScene1 {
              // Configure the view.
  
              let skView = self.view as! SKView
  
              skView.showsFPS = true
              skView.showsNodeCount = true
              skView.showsPhysics = false
  
              /* Sprite Kit applies additional optimizations to improve rendering performance */
              skView.ignoresSiblingOrder = true
  
              /* Set the scale mode to scale to fit the window */
              scene.scaleMode = .AspectFill
  
              skView.presentScene(scene)
  
          }
  
  
      }
  </code></pre>
  
  <p>Then here I set up my <code>GameOverScene1.swift</code> file: </p>
  
  <pre><code>import SpriteKit
  
  class GameOverScene1: SKScene {
  
      override func didMoveToView(view: SKView) {
  
          //Do stuff in scene
          println("it works!")
      }
  }
  </code></pre>
  
  <p>And the game runs without any errors or crashing but <code>GameOverScene1</code> isn't run; it just goes to <code>GameOverBufferViewController</code>. Nothing is printed to the console either. </p>
  
  <p>What am I doing wrong?</p>
  
  <p>EDIT********</p>
  
  <p>This is what my <code>GameOverBufferViewController</code> file looks like now and I get a <code>SIGABRT</code> error saying <code>could not cast a UIView as an SKView</code>:</p>
  
  <pre><code>import UIKit
  import SpriteKit
  
  class GameOverBufferViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // Do any additional setup after loading the view.
              // Configure the view.
  
              back()
  
  
      }
      func back() {
          view.subviews.map({ $0.removeFromSuperview() })
  
          let theView = view as! SKView //error on this line
          let theMainMenu = GameOverScene( size: view.frame.size )
          theMainMenu.scaleMode = SKSceneScaleMode.ResizeFill
  
          theView.presentScene( theMainMenu )
  
      } 
  </code></pre>