Tab Bar Controller in SpriteKit

I want to program a game with a tab bar controller. I have added a tabbar controller to a ViewController with a button segue and a new file with the scene to be displayed is programmed to the respective view controller of the Tab bar. But the error message "Could not CastValue of type 'UIView' (0x10dfede60) to 'SKView' (0x10cdba800). (Lldb") on (I have also created a new gamecene). What have I done wrong or is there an easier way for this?


PS: I am a Swift beginner, so do not take it so bad, if I am not very know.



The view conztrollers of the tab bar:



import UIKit

import SpriteKit

class SecondViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

if let view = self.view as! SKView? {

/

if let scene = SKScene(fileNamed: "secondScene") {

/

scene.scaleMode = .aspectFill

/

view.presentScene(scene)

}

view.ignoresSiblingOrder = true

view.showsFPS = true

view.showsNodeCount = true

}

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

/

}


/

/

/

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

/

/

}

*/

}




The GameViewController:



import UIKit

import SpriteKit

import GameplayKit

class GameViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

if let view = self.view as! SKView? {

/

if let scene = SKScene(fileNamed: "GameScene") {

/

scene.scaleMode = .aspectFill

/

view.presentScene(scene)

}

view.ignoresSiblingOrder = true

view.showsFPS = true

view.showsNodeCount = true

}

}

override var shouldAutorotate: Bool {

return true

}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {

if UIDevice.current.userInterfaceIdiom == .phone {

return .allButUpsideDown

} else {

return .all

}

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

/

}

override var prefersStatusBarHidden: Bool {

return true

}

}

Replies

This error means that the configuration of your UIViewControllers in main.storyboard have not be set up for SpriteKit views (SKView). [See the linked screenshot for steps to do this]


0) open Xcode's right-sidebar

1) select your Main.storyboad in the Xcode file navigator

2) select views & controllers objects

3) filter on "skview"

4) select the UIView and hit delete. Replace it with a SpriteKit View from the views & controllers objects marked by #2.


Because you said this is a tabbed SpriteKit app, repeat these steps for any other view controllers in your root tab view controller that use SKView.