I know there are answers for passing data backwards, but they are for consecutive view controllers. I have 3 view controllers and a navigation controller. All segues are "show segue". I would like to pass data from VC3 to VC1. I'm trying to use delegate, but getting stuck:
protocol Delegate:class {
func getCityId(with id: String)
}
Class VC3:UIViewController{
weak var delegate: Delegate?
let id:String?
func passDataBackwards() {
delegate?.getCityId(with: self.id!)
}
}
Class VC1:UIViewController, Delegate{
func getCityId(with id: String) {
print ("id from search: \(id)")
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let vc3 = (segue.destination as! VC3)
vc3.delegate = self
}
}
My problem is that I have 2 segues between my source and destination. Your kind help will be appreciated.
sourceViewController
property of the storyboard segue passed its unwind method to get a reference to VC3. It can then read the required data from a property of vc3 – Paulw11