Search code examples
iosscenekit

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


App was building fine until I started adding buttons to the storyboard then I got the above error. It stops at this line of code inside my GameViewController.

let scnView = self.view as! SCNView

The storyboard itself has its custom class set to GameViewController (theres no option for SCNView). GameViewController itself inherits from UIViewController. Im using Xcode7.2.


Solution

  • Make sure to also import SceneKit at the top of the file.

    import SceneKit
    

    Open the “Main.storyboard” File. Select ViewController -> View go to “Identity Inspector” and change the Class field to SCNView. SceneKit Help