0

I have a segue to a view controller which is in charge of authenticating the user. When the use is signed in, I want to go back to the parent view controller. Following this guide, I have created a segue from the auth view controller to it's exit. When I try to call it in code, I nothing happens.

Here is my code:

import UIKit

import Firebase
import FirebaseAuth
import GoogleSignIn

class AuthVC: UIViewController, GIDSignInUIDelegate {

    @IBAction func unwindAuth(sender: UIStoryboardSegue) {
        print("'unwindAuth' called")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        GIDSignIn.sharedInstance().uiDelegate = self

        FIRAuth.auth()?.addStateDidChangeListener() { (auth, user) in
            if FIRAuth.auth()?.currentUser != nil {

                print(self.shouldPerformSegue(withIdentifier: "unwindSegue", sender: nil))

                self.performSegue(withIdentifier: "unwindAuthSegue", sender: nil)

            }
        }
    }
}

After clicking the sign in button, I get true in the console from self.shouldPerformSegue, but nothing else (no errors and nothing happens).

I am using Xcode Version 8.3 beta (8W109m).

I have been searching for a solution to this for a few days.

Disclaimer: I am new to Xcode, but I have been programming for almost 10 years. I have no formal training, though.

  • 2
    You didn't read it very closely: "..you specify the name of an unwind action in the view controller you want the segue to unwind to". You have put it in the view controller you are unwinding from. – Gruntcakes Feb 04 '17 at 17:00
  • Thanks for the answer. Is there any way to do it the other way around? I can listen for signin from the first controller, but to know that it was from the auth view controller I would have to set some kind of state variable. It doesn't seem like best practice. Also, why didn't I get an error instead of just nothing? – Fallenalien22 Feb 04 '17 at 17:45
  • Sounds like you want to pass back data from the 2nd view controller to the 1st? There's plenty of past questions on how to do that if you look around. – Gruntcakes Feb 04 '17 at 17:56
  • Ok thanks. Create an answer and I'll select it. – Fallenalien22 Feb 04 '17 at 17:58

1 Answers1

3

The unwind segue action must be placed on the view controller to which you want to segue back to, not on the view controller you are leaving.

If you wish to pass data back then you can use a delegate

Passing data back from view controllers Xcode

Community
  • 1
  • 1
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • Thanks a bunch. It works now. All I had to do was place the `@IBAction func` in the parent view controller. The `self.performSegue` has to go in the child view controller, as the segue belongs to that class, so I didn't even need the link. – Fallenalien22 Feb 04 '17 at 18:24