Passing variables between storyboards without Segues - Swift

I am passing data between two different UIViewControllers located in two different .storyboard files in Xcode. (This is a fairly large project, so I had to split it into different storyboards.)

I already set the variable "exercisePassed" (String) in the view to which I would like to pass my data, and I already know how to navigate between two views located in different storyboards. Like this.

var storyboard = UIStoryboard(name: "IDEInterface", bundle: nil) var controller = storyboard.instantiateViewControllerWithIdentifier("IDENavController") as! UIViewController //************************************** var ex = //Stuck Here ex.exercisedPassed = "Ex1" //************************************** self.presentViewController(controller, animated: true, completion: nil) 

How to transfer data without using Segue / PrepareForSegue?

+5
source share
4 answers

I assume that the viewController to which you want to pass data is a custom viewController. In this case, use this modified code here:

 var storyboard = UIStoryboard(name: "IDEInterface", bundle: nil) var controller = storyboard.instantiateViewControllerWithIdentifier("IDENavController") as! MyCustomViewController controller.exercisedPassed = "Ex1" self.presentViewController(controller, animated: true, completion: nil) 
+21
source

Your question is not very clear, as I understand it

 //1 //create a variable in "IDENavController" //eg var someVariable = @"" //2 var controller = storyboard.instantiateViewControllerWithIdentifier("IDENavController") as! UIViewController controller.someVariable = [assign your variable] //3 self.presentViewController(controller, animated: true, completion: nil) 
+3
source

Try it. It worked for me.

 var storyboard = UIStoryboard(name: "IDEInterface", bundle: nil) var controller = storyboard.instantiateViewControllerWithIdentifier("IDENavController") as! YourDestinationViewControllername // Add your destination view controller name and Identifier // For example consider that there is an variable xyz in your destination View Controller and you are passing "ABC" values from current viewController. controller.xyz = "ABC" self.presentViewController(controller, animated: true, completion: nil) 

Hope this will be helpful.

+2
source

For those looking for Swift 3/4 answer:

 let storyboard = UIStoryboard(name: "IDEInterface", bundle: nil) let controller = storyboard.instantiateViewController(withIdentifier: "IDENavController") as! CustomViewController controller.yourVariable = "abc" self.present(controller, animated: true, completion: nil) 
+1
source

All Articles