ios - Passing Data between View Controllers in Swift -


i trying convert app objective-c swift can't find how pass data between views using swift. objective-c code is

uistoryboard *storyboard = [uistoryboard storyboardwithname:@"main" bundle:nil]; ansviewcontroller *ansviewcontroller; ansviewcontroller = [storyboard instantiateviewcontrollerwithidentifier:@"ansview"]; ansviewcontroller.num = thenum; [self presentviewcontroller:ansviewcontroller animated:yes completion:nil]; 

what doing takes variable, thenum, , passes variable, num, on different view controller. know may easy question getting pretty confused swift if explain how changed swift appreciated!

thanks

let's assumed stand @ firstview go detailview , want passing data firstview detailview. storyboard, @ firstview have method:

override func prepareforsegue(segue: uistoryboardsegue!, sender: anyobject!) {     if (segue.identifier == "seguetest") {       //checking identifier crucial there might multiple       // segues attached same view       var detailvc = segue!.destinationviewcontroller detailviewcontroller;       detailvc.topass = textfield.text     } } 

and class of detailview declared variable:

var topass: string! 

then can use variable topass (of course can change type of variable want, in ex demo string type).


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -