How do I change viewControllers in swift with Foundation Xcode

93 Views Asked by At

I am trying to programmatically switch to another viewController scene when a certain event happens in Xcode for a MacOS app but am having trouble. The second view controller is in the same storyboard as the one I am trying to switch from. I currently have

let secondViewController = ViewController(nibName: "outcome", bundle: nil)
            self.present(secondViewController, animator: true as! NSViewControllerPresentationAnimator)

but it seems to crash when the event is triggered:

Could not cast value of type 'Swift.Bool' (0x2010043a8) to '__C.NSViewControllerPresentationAnimator' (0x2007787d0).

it also shows an error Thread 1: signal SIGABRT on the second command where I self.present

1

There are 1 best solutions below

3
Teodor On

you are trying to cast a bool to NSViewControllerPresentationAnimator

try this code instead:

let secondViewController = ViewController(nibName: "outcome", bundle: nil)
 self.present(secondViewController, animator: true)