title: How to programmatically launch into another viewController if your user is logged in through Facebook
body: <p>Basically I have one class called facebookLogin.swift, the login page, and ViewController.Swift the homepage. I have correctly coded all the Facebook login stuff and it all works, I can log in and log out with both the button the FBSDK provides as well as the custom button I have defined. However, I can not figure out how to go to the ViewController.swift page if the user is logged in.</p>
  
  <p>Here is the facebookLogin.swift code:</p>
  
  <pre><code>import UIKit
  import FBSDKCoreKit
  import FBSDKLoginKit
  
  class facebookLogin: UIViewController, FBSDKLoginButtonDelegate {
      var loginStatus = false;
  
      @IBOutlet weak var facebookOutlet: UIButton!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          super.viewDidLoad()
          let loginButton  = FBSDKLoginButton()
          view.addSubview(loginButton)
          loginButton.center = view.center
          loginButton.delegate = self;
          loginButton.readPermissions = ["email","public_profile"]
      }
  
      @IBAction func facebookAction(_ sender: Any) {
          customFBLogin()
          if (FBSDKAccessToken.current() != nil) {
              NSLog("it works")
          }
      }
  
      func customFBLogin() {
          FBSDKLoginManager().logIn(withReadPermissions: ["email","public_profile"], from: self) { (result, err) in
              if err != nil {
                  print("Facebook Login Error Failed \(err)")
                  return;
              }
              self.showEmailAddress();
              self.loginStatus = true;
          }
      }
  
  
  
      func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
          print("Did log out of Facebook")
      }
  
      func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
          if error != nil {
              print(error)
              return;
          } else {
              print("Successfuly logged into Facebook");
              showEmailAddress()
  
          }
      }
  
      func showEmailAddress() {
          FBSDKGraphRequest(graphPath: "/me", parameters: ["fields": "id, name, email"]).start(completionHandler: { (connection, result, err) in
  
              if err != nil {
                  print("Failed to start graph request \(err)")
                  return;
              }
              print(result)
  
          })
      }
  
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
  
      /*
      // MARK: - Navigation
  
      // In a storyboard-based application, you will often want to do a little preparation before navigation
      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
          // Get the new view controller using segue.destinationViewController.
          // Pass the selected object to the new view controller.
      }
      */
  
  }
  </code></pre>
  
  <p>Here is the relevant code from the AppDelegate.swift file: </p>
  
  <pre><code>import UIKit
  import CoreData
  import Firebase
  import FBSDKCoreKit
  
  @UIApplicationMain
  class AppDelegate: UIResponder, UIApplicationDelegate {
  
      var window: UIWindow?
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool {
          // Override point for customization after application launch.
          FIRApp.configure()
          FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
  
          let mainStoryBoard = UIStoryboard.init(name: "Main", bundle: nil)
          self.window = UIWindow(frame: UIScreen.main.bounds)
          var initialViewController: UIViewController
  
          if(FBSDKAccessToken.current() != nil) {
              let vc = mainStoryBoard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
              initialViewController = vc
          } else{
              initialViewController = mainStoryBoard.instantiateViewController(withIdentifier: "facebookLogin")
          }
  
          self.window?.rootViewController = initialViewController
  
          self.window?.makeKeyAndVisible()
  
          return true
      }
  
      func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -&gt; Bool {
          let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
  
          return handled;
      }
  </code></pre>
  
  <p>In the first application function in the AppDelegate.swift class, I have found another tutorial on stackoverflow which suggested using this code. I inputted the code and converted the syntax to swift3, but the app breaks when I launch it. This means that it knows that I am logged in but for some reason the segue does not load and it breaks the app. The error I get is Thread 1: sigabrt.</p>
  
  <p>Here is how the relevant items in the story board look, at first the initial view Controller is on the left and if the user is logged in I want the app to start from the viewController on the right
  <a href="https://i.stack.imgur.com/3EEL5.png" rel="nofollow noreferrer">1</a></p>