Could Not Cast Value of Type 'Uiview' (0X112484Eb0) to 'Skview' (0X111646718)

Could not cast value of type 'UIView' (0x112484eb0) to 'SKView' (0x111646718)

I finally fixed it! Instead of putting the functions in the GameViewController and calling them from game scene, I had to put the functions in gameScene and replace view with self.view!.

Swift Could not cast value of type 'UIView' to 'SKView'

Looking at your answer, you appear to be using the main view of your PopupViewController to add the scene to, rather than the new sceneView that you declared. The first way to fix this is, as said by Nathan Hitchings in the comments, to override loadView and set self.view = sceneView. The other option is to open your storyboard or .xib and set the class type of the main view to be SKView and then you can delete the sceneView variable entirely and work with self.view. Both essentially do the same thing, but in two different ways. Ensure that you give sceneView a value before using it too, as currently it appears to stay uninitialised. Let me know if you need me to clarify anything.

The first option would look something like this:

override func loadView() {
sceneView = SKView()
sceneView.backgroundColor = .white

self.view = sceneView
}

Could not cast value of type 'UIView' to 'SKView' (removed Storyboard)

This is where your mistake is:

let skView = view as! SKView

You are assuming that self.view is an instance of SKView, but it isn't. It's a UIView, just like how in the storyboard, the root view by default has the class UIView.

You should instead do:

let skView = SKView()
view = skView

To set the root view to an instance of SKView.

Could not cast value of type 'UIView' (0x1102beb40) to 'SKView' (0x10f0814c8)

i had the same problem before. Go to your storyboard and in your identity inspector, set custom class to SCNView

//set custom class to SCNView

Could not cast value of type 'UIView' to 'SCNView'

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

How to bring an SKSprite in front of a storyboard's UI?

You should add UIView to Storyboard, then define UIView as SKView. You can check how to do it: Could not cast value of type 'UIView' (0x112484eb0) to 'SKView' (0x111646718) Then you will be able present SKScene inside this SKView.

    let skView = self.view as! SKView

skView.presentScene(GameScene(size: skView.bounds.size))

SKView to UIView

SKView is a subclass of UIView. Everywhere you can use a UIView, you can also use an SKView. You can

go from an SKView to an UIView

simply by casting it. For example:

let view = spriteKitView as UIView

Thread 1 signal SIGABRT crash when casting UIView to SKView

You are getting a crash because your UIView's (i.e. your self.view) actual type is NOT an SKView. So you can't downcast to an SKView because it is not an SKView. So wherever you create your ViewController's view you must be assigning it a UIView. You said you are not using storyboards so I assume you are creating the ViewController programmatically. If this is the case, you need to manually assign your ViewController's view an SKView. This is typically done in the loadView method of the ViewController. You can see an example of this here



Related Topics



Leave a reply



Submit