0
votes

I just spent couple of days for trying to figure this out for mac app, but not doing it successfully.

I have first ViewController and second ViewController. Let's say, ViewControllerA(VC-A) and ViewControllerB(VC-B). In Main.storyboard, they are connected by segue with identifier "PromptToUser".

VC-B gets triggered not by button, but if condition during the process.
It is triggered by:

performSegue(withIdentifier: "PromptToUser", sender: self)

in VC-A.

In VC-A, I put the followings so far:

override func prepare(for segue: NSStoryboardSegue, sender: Any?) { }

In VC-B, so far, I have:

@IBOutlet weak var Login: NSTextField!
@IBOutlet weak var Pass: NSSecureTextField!

VC-B also has a button which I want to make as a trigger to collect information entered by user for above variables and send it back to first view.

I found many similar topics on this in stackoverflow. However, it seems most of them are for iOS, but not for mac app as I could not make UI... and other classes (delegates) and protocols they mentioned to be recognized for Swift 3 environment. I have NSViewController, and NS... not UI...

What would be the best way to approach this for mac app with Swift 3?

1

1 Answers

0
votes

You Can make a static variable in VC-A and just update the value of static variable from VC-B. Example

In VC-A

static var login = ""
static var password = ""

In VC-B

VC-A.login =  nameTextField.text
VC-A.password = passTextField.text

Write the code in SaveButton Action of VC-B, and you will get the update value in VC-A. If You are not using any Save Button in VC-B, then You can write code in viewWillDisappear Method of VC-B

    override func viewDidDisappear(_ animated: Bool) {
          firstVC_A.login =  nameTextField.text
          firstVC_A.password = passTextField.text

    }