Max Vecheslavov Max Vecheslavov - 1 year ago 253
Swift Question

macOS, Swift 3: How to get data back after segue?

For example: I have two

s. The first has a button and a
, and the second has a

When I click the button on the first controller — the second controller shows as popover window.

Making a transfer of some data from first controller to second is not big deal — I use a segue. But what I should to do to transfer data back — from the popover window to main window?
For example: we open the popover window, type some text in
, and I want to get this text in the
of the first

I can't find the answer :-(

Answer Source

In macOS it's pretty easy if you are using storyboard and segues.

NSViewController has a property presenting which contains a reference to the parent view controller.

Obtain the reference, call a method in the parent view controller to pass the data and dismiss the child view controller.

let firstViewController = presenting as! FirstViewController
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download