Custom segues do not load new view's touchbar!

I’ve been going at this for nearly the last 6 hours so am desperately hoping somebody on these threads can help me out.

I have a simple touch bar app with two main views. I’d like to segue between the views by replacing one view with the other in the window. To do this I wrote a simple custom segue (fig.1):

When I use the built-in segues – which I do not want to use as I want to stay in window without animation – the window segues and the touchbar reloads to the new ViewController’s window. When I use this custom segue, however, the touchbar stays as that of the original ViewController and breaks afterwards when its buttons are pressed.

I’ve tried for hours and hours to figure out a proper fix for this but can’t come up with anything. Here is my github repo: Feel free to open up and look around. Right now the segues are set to my custom segue; set them to a segue like Sheet to see how touchbar segue should function.

Thank you indefinitely if you can put an end to this misery.

Figure 1:
override func perform() {
if let fromViewController = sourceController as? NSViewController {
if let toViewController = destinationController as? NSViewController {
fromViewController.view.window?.contentViewController = toViewController

hi @zhammer,
I hope you have a solution to this issue.

  1. If you are using segue’s then why are you setting the contentViewController manually?
  2. from a code perspective try using something like
    if let fromViewController = sourceController as? NSViewController,
       let toViewController = destinationController as? NSViewController {
        // do whatever here

This will work better than nesting if statements