sprite-kit SKView Create a full screen SKView using Interface Builder


A typical use case for SpriteKit is where the SKView fills the whole screen.

To do this in Xcode's Interface Builder, first create a normal ViewController, then select the contained view and change its Class from UIView to SKView:

enter image description here

Within the code for the View Controller, in the viewDidLoad method, grab a link to this SKView using self.view:

In Swift:

guard let skView = self.view as? SKView else {
    // Handle error

(The guard statement here protects against the theoretical error that the view is not an SKView.)

You can then use this to perform other operations such as presenting an SKScene:

In Swift: