How to segue programmatically in iOS using Swift

I’m creating an app that uses the Facebook SDK to authenticate users. I’m trying to consolidate the facebook logic in a separate class. Here is the code (stripped for simplicity):

import Foundation

class FBManager {
    class func fbSessionStateChane(fbSession:FBSession!, fbSessionState:FBSessionState, error:NSError?){
        //... handling all session states
        FBRequestConnection.startForMeWithCompletionHandler { (conn: FBRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
        
            println("Logged in user: \n\(result)");
        
            let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
            let loggedInView: UserViewController = storyboard.instantiateViewControllerWithIdentifier("loggedInView") as UserViewController
        
            loggedInView.result = result;
        
            //todo: segue to the next view???
        }
    }
}

I’m using the above class method to check session state changes, and it works fine.

Q: Once I have the user’s data, how can I segue to the next view from within this custom class?

Just to be clear, I have a segue with identifier on the storyboard, and I’m trying to find a way to perform a segue from a class which is not the view controller

11 Answers
11

Leave a Comment