Reputation: 119
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.
Upvotes: 3
Views: 3877
Reputation: 2040
If you're doing this programmatically, add the following code:
override func loadView() {
//sort of like changes type of self.view from UIView to SCNView
self.view = SCNView()
}
Upvotes: 1
Reputation: 1
Same thing happened to me when I deleted a UIButton, which also deleted the UIView. So add a UIView and change class to SCNView
Upvotes: 0
Reputation: 144
If you are setting all these stuff programmatically without storyboard, make sure to do these steps:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow()
let gameViewController = GameViewController()
window?.rootViewController = gameViewController
window?.makeKeyAndVisible()
return true
}
let scnView = SCNView(frame: view.frame)
view.addSubview(scnView)
Upvotes: 6
Reputation: 1845
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
Upvotes: 8