Dmitry Klochkov Dmitry Klochkov - 4 months ago 44
iOS Question

Create SKView programmatically?

I like my code to be explicit so I want to remove the storyboard file and create SKView programmatically.

What I have tried so far:

  1. I created a SpriteKit game project in xcode.

  2. Deleted the storyboard file.

  3. Deleted sroryboard property from

  4. Added this code found in an example to the

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    AppViewController *viewController = [[AppViewController alloc] init];
    viewController.edgesForExtendedLayout = UIRectEdgeNone;
    _window.rootViewController = viewController;
    [_window makeKeyAndVisible];
    return YES;


  5. Added this code to the

    -(void) loadView
    self.view = [[SKView alloc] init];

The app starts but then crashes on the creation of first sprite with the following warning


I think there should be some good examples of how to do this, but I have not found any for the Sprite Kit yet.


I fixed the problem by setting a frame to the view:

- (void) loadView
    self.view = [[SKView alloc] initWithFrame: [[UIScreen mainScreen] bounds]];

Here is a working example project in Swift