1

I'm trying to pass few variables via a segue. Initially I capture 6 variables on the first screen which I would like to pass on to the second view controller.

Each variable is captured through a text box capturing an integer and I called them T1, T2, T3 ... T6. At present I refer to the value through T1.text.toInt()!. Before I pass these values via segue, should I first create a variable like var T1 = T1.text.toInt()! ?

What is the best way of designing this?

DanteDeveloper
  • 287
  • 2
  • 5
  • 12
  • You should find this post helpful. http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – Adrian Apr 19 '15 at 00:50

1 Answers1

0

inside prepareForSegue you have access to the UIController instance that will open:

class FirstPageUIViewController:UIViewController {
...

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    var controller = (segue.destinationViewController as! MyNextViewController)
    controller.T1 = "value to pass"
  }

}

This means you define you variables in MyNextViewController (the controller for your second screen) and the variables are already set when your MyNextViewController instance takes over control.

You also might decide to name your variables starting with small letters according to the swift style guide.

Gerd Castan
  • 6,275
  • 3
  • 44
  • 89