Fiducial13 Fiducial13 - 6 months ago 72
Swift Question

How do I perform an auto-segue in Xcode 6 using Swift?

I wish to auto-segue from the main viewController to a second view controller after a set period of time after an app loads.

How do I do this?

Do I need to do it programmatically?


If your UI is laid out in a Storyboard, you can set an NSTimer in viewDidLoad of your first ViewController and then call performSegueWIthIdentifier when the timer fires:

class ViewController: UIViewController {

    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.
        let timer = NSTimer.scheduledTimerWithTimeInterval(8.0, target: self, selector: #selector(timeToMoveOn), userInfo: nil, repeats: false)

    func timeToMoveOn() {
        self.performSegueWithIdentifier("goToMainUI", sender: self)

Here is how you set up the segue in the Storyboard:

  1. Control drag from the File's Owner icon of the first ViewController to the second ViewController.
  2. Choose "modal" from the pop-up.

Seting up the segue

  1. Click on the segue arrow that appears between the view controllers. In the Attributes Inspector for the segue...
  2. Give your segue an Identifier.
  3. Turn off Animates if you don't want to see the screen slide in.

enter image description here