View Controller Transitions

I have 3 view controllers (Lets call them A, B, C).

From A i can go to B
From B i can go to C

My goal is so that when i dismiss C it takes me all the way back to A and not B.

So my question is, If you have 3 view controllers stacked on top of eachother, is there a way to dismiss the middle layer while the top layer is presenting?

have you tried using popToRootViewController instead of popViewController?

I’m not using a navigation controller which made things more tricky, the solution was

self.view.window!.rootViewController.dismiss(animated: true, completion: nil)