I need to send data from HomeVC to ResultVC using segue, is this kind of method violate MVC? Inside the ResultVC I created two store properties so that I can access to it in the prepare(for segue: UIStoryboardSegue, sender: Any?) method in HomeVC, can anyone please tell me whether this kind of method violate MVC? Your responses will be highly appreciate!
Code Block class HomeVC:UIViewController { override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == C.segueToResultVC { let resultVC = segue.destination as! ResultVC resultVC.totalSplit = calculator.getSplit() resultVC.splitInfo = calculator.splitInformation() } } } class ResultVC:UIViewController { var totalSplit:String? var splitInfo:String? override func viewDidLoad() { super.viewDidLoad() customizeViews() } override func viewWillAppear(_ animated: Bool) { totalPrice.text = totalSplit splitAndTip.text = splitInfo }
That is the right way of doing it.
Just one comment.
On line 4, you take a risk (very limited) by forcing downcast.
You'd better write
Just one comment.
On line 4, you take a risk (very limited) by forcing downcast.
You'd better write
Code Block if let resultVC = segue.destination as? ResultVC { resultVC.totalSplit = calculator.getSplit() resultVC.splitInfo = calculator.splitInformation() }