Pass variables using CurrentViewController in Swift

I am working on a fast application and I created links to other views using presentViewController , but I cannot figure out how to pass variables. How to pass variables to a new view?

 @IBAction func WorkoutPressed(sender: AnyObject) { let storyBoard = UIStoryboard(name: "Main", bundle:nil) let workoutView = storyBoard.instantiateViewControllerWithIdentifier("workoutView") as WorkoutViewController self.presentViewController(workoutView, animated: false, completion: nil) //self.navigationController?.pushViewController(workoutView, animated: true) } 

thanks

+5
source share
1 answer

This is simpler than you think: you do not need to pass parameters, because you can directly access the class variables of the next controller.

That is, you can do something like this:

 workoutView.myVar = myVal 

And, when this view loads, myVar will have the value myVal . (Remember to declare it in the WorkoutViewController , though).

+8
source

Source: https://habr.com/ru/post/1208472/


All Articles