-1

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

de.
  • 7,068
  • 3
  • 40
  • 69
Ninten
  • 11
  • 1
  • 2
    Check the syntax of the present method. you definitely don't want an 'as!' in there. – john elemans Feb 11 '22 at 16:13
  • `true` isn't an animator. See [present(_:animator:)](https://developer.apple.com/documentation/appkit/nsviewcontroller/1434431-present). The animator should be a [NSViewControllerPresentationAnimator](https://developer.apple.com/documentation/appkit/nsviewcontrollerpresentationanimator). "You might find what you need in the NSViewController.TransitionOptions enumeration, which provides many predefined animations." – Willeke Feb 11 '22 at 17:10

1 Answers1

-1

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)
Teodor
  • 1
  • 1