I have a pretty complicated function generating a value in one view controller (lets call it firstVC
). This value is used in firstVC
but I would also like to utilize this value in other view controller at a later time (which we'll call thirdVC
). I know I could set up a protocol to rerun the function, but this would just take extra time and I would rather just pass the value. No segue exists between firstVC
and thirdVC
and the time at which thirdVC
will be opened and utilize the value is unknown and will be at some later time. (I can still get to thirdVC
by seguing: firstVC
-> secondVC
-> thirdVC
). I thought one could set it up as follows:
//In firstVC
var currentVal: String = "Hello"
@IBAction func button(_ sender: UIButton){
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let thirdVC: thirdVC = storyBoard.instantiateViewController(withIdentifier: "thirdVC")
thirdVC.passedValue = currentVal
}
With passedValue
being a variable living in thirdVC
. This, however, does not pass any information as when I try to check the passedValue
on the thirdVC
's viewDidLoad()
it is empty... I also try checking the value later via a button (to ensure that viewDidLoad()
running before the info is passed isn't the issue) and it is still empty.