presentScene Error

So I’ve made this mistake twice recently, and anytime that happens I tend to thoroughly document my problem and it’s solution. It’ s a kind of “Fool me Once” Attitude.

So this neat little error occurs when I’ve made a new UIView and try to add a new SKScene to the ViewController. When you add an SKScene, you’ll use the SKView  presentScene method to do so. Normally, you’ll fetch the main view of your presenting UIViewContoller to do this, but when I’ve added a brand spanking new UIViewController to my project and then attempt to present an SKScene, I’ll get this error:

Shot-1

This error message pops up because we’re trying to send the presentScene selector to a UIView, instead of an SKView.

You see, when you make a new UIViewController it’s view object will default to an instance of UIView instead of an SKView.

Fixing this is pretty simple, though.

You just have to change the class of your new UIViewController’s view object in the interface builder to an SKView.

Shot-2

 

And now you’re ready to rock and roll!