wadda_wadda
wadda_wadda

Reputation: 1004

Could not instantiate class named SCNView

I'm getting this error when I try to launch my app. My app should just be an empty SKScene in view. From my understanding this is usually caused by not importing the proper frameworks. I already have my UIKit and SpriteKit framework linked, and those are the only two frameworks I'm using.

Following is my ViewController code:

import UIKit
import SpriteKit

class GameViewController: UIViewController {

    var scene: GameScene!


    override func viewDidLoad() {
        super.viewDidLoad()

        // Configure the view
        let skView = view as SKView
        skView.multipleTouchEnabled = false

        //Create and configure the scene
        scene = GameScene(size: skView.bounds.size)
        scene.scaleMode = .AspectFill

        // Present the scene.
        skView.presentScene(scene)

    }

    override func prefersStatusBarHidden() -> Bool {
        return true
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Release any cached data, images, etc that aren't in use.
    }

}

Following is my GameScene code:

import UIKit
import SpriteKit



let HurdleSize:CGFloat = 20.0
let TickLengthLevelOne = NSTimeInterval(600)

class GameScene: SKScene {
    var tick: (() -> ())?
    var tickLengthMillis = TickLengthLevelOne
    var lastTick:NSDate?

    var textureCache = Dictionary<String, SKTexture>()

    override init(size: CGSize) {
        super.init(size: size)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

and following is my error trace:

  Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named SCNView'
  *** First throw call stack:
  (
    0   CoreFoundation                      0x0161d946 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x01e1ca97 objc_exception_throw + 44
    2   CoreFoundation                      0x0161d86d +[NSException raise:format:] + 141
    3   UIKit                               0x007bfd74 UINibDecoderDecodeObjectForValue + 317
    4   UIKit                               0x007bfc2f -[UINibDecoder decodeObjectForKey:] + 371
    5   UIKit                               0x00629bf1 -[UIRuntimeConnection initWithCoder:] + 189
    6   UIKit                               0x007bff1a UINibDecoderDecodeObjectForValue + 739
    7   UIKit                               0x007c011c UINibDecoderDecodeObjectForValue + 1253
    8   UIKit                               0x007bfc2f -[UINibDecoder decodeObjectForKey:] + 371
    9   UIKit                               0x00628ea7 -[UINib instantiateWithOwner:options:] + 1164
    10  UIKit                               0x0044b624 -[UIViewController _loadViewFromNibNamed:bundle:] + 270
    11  UIKit                               0x0044bdbb -[UIViewController loadView] + 295
    12  UIKit                               0x0044bfef -[UIViewController loadViewIfRequired] + 78
    13  UIKit                               0x0044c595 -[UIViewController view] + 35
    14  UIKit                               0x00343825 -[UIWindow addRootViewControllerViewIfPossible] + 66
    15  UIKit                               0x00343c99 -[UIWindow _setHidden:forced:] + 287
    16  UIKit                               0x00343f50 -[UIWindow _orderFrontWithoutMakingKey] + 49
    17  UIKit                               0x0035228d -[UIWindow makeKeyAndVisible] + 80
    18  UIKit                               0x002ef776 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3108
    19  UIKit                               0x002f2c0d -[UIApplication _runWithMainScene:transitionContext:completion:] + 1639
    20  UIKit                               0x0030b7d0 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 59
    21  UIKit                               0x002f181f -[UIApplication workspaceDidEndTransaction:] + 155
    22  FrontBoardServices                  0x0745f9de __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
    23  FrontBoardServices                  0x0745f46f __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
    24  FrontBoardServices                  0x07471425 __31-[FBSSerialQueue performAsync:]_block_invoke + 26
    25  CoreFoundation                      0x015411c0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
    26  CoreFoundation                      0x01536ad3 __CFRunLoopDoBlocks + 195
    27  CoreFoundation                      0x0153692b __CFRunLoopRun + 2715
    28  CoreFoundation                      0x01535bcb CFRunLoopRunSpecific + 443
    29  CoreFoundation                      0x015359fb CFRunLoopRunInMode + 123
    30  UIKit                               0x002f11e4 -[UIApplication _run] + 571
    31  UIKit                               0x002f48b6 UIApplicationMain + 1526
    32  HurdleJumpr                         0x000a88cf main + 111
    33  libdyld.dylib                       0x03cbfac9 start + 1
  )
  libc++abi.dylib: terminating with uncaught exception of type NSException

Upvotes: 1

Views: 4072

Answers (2)

tbago
tbago

Reputation: 680

I have the same issue,when my project template is Single View Application.Because Xcode not automatic add SceneKit.framework. You have to add it manually.

Upvotes: 12

Mundi
Mundi

Reputation: 80271

Looks like you have mistyped a class name in storyboard. Make sure the names of all the custom classes in your storyboard and xib files are correct.

Upvotes: 1

Related Questions