title: How can I create a segue programmatically to pass info between view controllers - Swift
body: <p>I'm new in swift, and I haven't found any answers about this. I have an game, where there's a slider, and a random value, so the user has to guess the value on the slider. When the user guesses the number, and presses the ok button it calls a view controller. When he gets pretty close, it calls another view controller, and finally if he doesn't guess it, it calls another one and the user restarts. My question is, how can I create a segue programmatically in order to pass the points earned and the rounds to each of the view controllers by just pressing ok. Those view controllers are created in the storyboard, and I call them by code</p>
  
  <p>Thanks for your help!</p>
  
  <pre><code>@IBAction func okButton(sender: AnyObject) {
  
      let diferencia = abs(targetValue - currentValue)
      var point = 100 - diferencia
      score += point
  
      func bonusPoints() {
      score += 100
      }
      if diferencia == 0 {
  
          let viewController3 = self.storyboard!.instantiateViewControllerWithIdentifier("GonPerfectViewController") as UIViewController
          presentViewController(viewController3, animated: true, completion: nil)
          point += 100
          newRound()
          updateLabel()
          bonusPoints()
              } else if diferencia &lt; 4 {
  
              let viewController3 = self.storyboard!.instantiateViewControllerWithIdentifier("GonNiceTry1ViewController") as UIViewController
              presentViewController(viewController3, animated: true, completion: nil)
              point += 50
              newRound()
              updateLabel()
  
               } else {
  
          let viewController3 = self.storyboard!.instantiateViewControllerWithIdentifier("GonThirdViewController") as UIViewController
          presentViewController(viewController3, animated: true, completion: nil)
  
          startnewgame()
          updateLabel()
  
      }
  }
  </code></pre>