Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variables between Storyboards without Segues - Swift

I'm passing data between two different UIViewControllers located within two different .storyboard files within Xcode. (It's quite a large project so I had to break it up into different storyboards.)

I have already established an "exercisePassed" variable (String) within the view I would like to Pass my data to, and I already know how to move between two views located within different storyboards. Like so.

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 can I pass the data without using a Segue/PrepareForSegue?

like image 569
Gavin Friel Avatar asked Aug 17 '15 13:08

Gavin Friel


1 Answers

I'm assuming that the viewController that you want to pass the data to is a custom viewController. In that case, use this amended 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)
like image 181
Swinny89 Avatar answered Sep 24 '22 16:09

Swinny89