How to: Return to NSViewController?

I'm coding an app for mac os (NOT ios) in Swift/xcode8. There are two NSViewControllers, Parent and Child (Child is called modally). What swift code is needed in both view controllers to segue or return from Child to Parent?


I have spent a good bit of time in the last several days searching the web for a solution (unwind, segue back, return). 99% of answers are for ios, and I can't find anything that will work.


I coded "@IBAction func unwindToViewController(sender: Any) {}" in Parent and can trigger it from a button in Child. Is my Paren action correct, and what do I need for code in Chile?

Replies

That's because iOS is window based singular, and macOS is multiple. When you can only work with one window (iOS), each VC (parent/child) can refer to the other and thus segue / 'go back', which in actually is a loop, not a reversed path. A>B>A


In macOS, with multiple windows, there is no VC to go back to/unwind/seque similar to iOS, as the flow is broken up at that point and the focus is on the window, not the VC.


Using the appropriate macOS call for your code to dismiss/close B should by default return focus to A.


See this SO thread for examples:


http://stackoverflow.com/questions/5711367/os-x-how-can-a-nsviewcontroller-find-its-window