Reputation: 57
CalViewController:
let brain =CalculatorBrain()
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let graph = GraphController()
graph.brain.record = brain.record
}
GraphViewController:
var brain = CalculatorBrain() {
didSet {
draw.variables = ["M": 1]
let value = brain.evaluate(using: draw.variables)
print(value)
//at that time outlet didn't set it prints the value work just fine
}
}
@IBOutlet weak var graphView: GraphView! {
didSet {
draw.variables = ["M": 1]
let value = brain.evaluate(using: draw.variables)
print(value)
//when outlet got set it not working it print nothing
}
}
I just can't figure out why and how to solve this any idea will be appreciate
Upvotes: 0
Views: 787
Reputation: 23701
The UIStoryboardSegue
contains the actual view controller that you are transitioning to in its destination property
. Instead of passing your data to that view controller, you are passing it to a brand new view controller that you create in prepareForSegue
(one which is promptly deleted when you leave the function).
You probably want something along the lines of:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let graph = segue.destination as? GraphController {
graph.brain.record = brain.record
}
}
I typed that without the benefit of a compiler so you may have to tweak it.
Upvotes: 1