Almeida Cavalcante Almeida Cavalcante - 10 months ago 45
Swift Question

Could not cast value of type 'SCNView' to 'SKView'

I'm following a tutorial to create a "tetris" game in Swift with XCode 7. I followed every single step in this tutorial, but I'm getting a runtime error:

Could not cast value of type 'SCNView' (0x106c19778) to 'SKView' (0x1068fcad0).

My GameViewController.swift is as follows:

import UIKit
import SceneKit
import SpriteKit

class GameViewController: UIViewController {

var scene: GameScene!
var swiftris:Swiftris!

override func viewDidLoad() {

//Configure the view
let skView = view as! SKView

skView.multipleTouchEnabled = false
//Create and configure the scene
scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .AspectFill
scene.tick = didTick
swiftris = Swiftris()

//Presente the scene.

self.swiftris.nextShape?.moveTo(StartingColumn, row: StartingRow)
let nextShapes = self.swiftris.newShape()
self.scene.addPreviewShpaeToScene(nextShapes.nextShape!) {}

override func prefersStatusBarHidden() -> Bool {
return true

func didTick(){
scene.redrawShape(swiftris.fallingShape!, completion: {})

I already search for it on google and here and I didn`t find anything related to SCNView and SKView.

Thank you in advance.

Answer Source

I did find the problem with my code. I instantiate the SKView as the view inside GameViewController:

self.view = SKView()    
let skView = view as! SKView

Before I do that, I tried to change the class of the view to SKView in the storyboard, but it was not possible.

I'd like to thank you for the revisions.