Search code examples
iosswiftparse-platformverification

Segues not executing when run using Swift and Parse


So I've set up my app to determine if there is a user and what to do if there is or is not. Also if they have verified their account (via phone number and sms) my issue is that when I run the app nothing happens. It loads and then just doesn't perform any of the segues. All segue identifiers are named correctly. currentUser variable has a value but numberIsVerified has no value. Im sure that has something to do with it but not sure what or how to fix it.

Code to determine where to take the user:

override func viewDidLoad() {
    super.viewDidLoad()

}

override func viewWillAppear(animated: Bool) {

    var currentUser = PFUser.currentUser()

    if currentUser == nil || currentUser!["phoneNumberVerified"] == nil {

        performSegueWithIdentifier("showInitialView", sender: self)

    } else {

        if let numberIsVerified = currentUser!["phoneNumberVerified"] as? Bool {

            if currentUser != nil && numberIsVerified == false {
                performSegueWithIdentifier("showVerifyUserView", sender: self)

            } else if currentUser != nil && numberIsVerified == true {
                performSegueWithIdentifier("showMyEventsView", sender: self)

            } else {
                performSegueWithIdentifier("showInitialView", sender: self)
            }
        }
    }
}

}


Solution

  • You can only use performSegueWithIdentifier when your view is fully loaded. So you can't segue from viewDidLoad. To fix this, move your segue to viewDidAppear:

    override func viewDidAppear(animated: Bool) {
    
    }
    

    update: i created a simple application that performs the segue for you to compare your code to:

    download project