First, I've reviewed the related questions:
- Error Could not cast value of type UIView to SKview
- Could not cast value of type 'UIView' (0x1102beb40) to 'SKView' (0x10f0814c8)
- Could not cast value of type 'UIView' (0x112484eb0) to 'SKView' (0x111646718)
None of those provided a clear answer for me, I'm unable to present a controller that has an SKView
in it from my main ViewController
, example:
import UIKit
import SceneKit
import SpriteKit
class ViewController: UIViewController {
var sceneView: SCNView!
var gameScene = GameScene()
var spriteScene: OverlayScene!
override func viewDidLoad() {
super.viewDidLoad()
sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))
sceneView.scene = gameScene
}
func showModal() {
let popupViewController = PopupViewController()
popupViewController.modalPresentationStyle = .popover
present(popupViewController, animated: true, completion: nil)
}
}
But the issue seems to be when the PopupViewController
is called:
import UIKit
import SpriteKit
class PopupViewController:UIViewController {
var sceneView:SKView!
var spriteScene:PopupScene!
override func viewDidLoad() {
view.backgroundColor = UIColor.green
view.scene = spriteScene
super.viewDidLoad()
}
}
The error is raised:
Could not cast value of type 'UIView' (0x1b48c69c8) to 'SKView' (0x1b3b254b0).