'How to hand over delegate to controller in different places of project

I have a UINavigationController which includes 4 screens. Each has a back button respectively. Task: by pressing the back button on Controller4 get to Controller2, which will immediately switch to Controller1. I want to do this through a delegate (connection of 2 and 4 controllers), but I don’t understand how I can access the ViewController4.delegate = self property in Controller2. There is already an action for clicking and switching to 3Controller, to do something like let storyboard = UIStoryboard(name: "VC4", bundle: nil) guard let vc4 = story.instantiateViewController(withIdentifier: "VC4") as? VC4 else { return } vc4.delegate = self } Please, help. How to link two controllers that are in completely different places in the project through a delegate (or something else)

P.S. This is my first time asking a question, sorry in advance if it's crooked

Example

protocol Controller2Delegate: AnyObject {
    func showVC1()
}

class Controller2: UIViewController, Controller2Delegate {
// need to connect between 2 and 4 controller
        let story = UIStoryboard(name: "VC4", bundle: nil)
        guard let vc4 = story.instantiateViewController(withIdentifier: "VC4") as? VC4 else { return }
        vc4.delegate = self //this is not work, and i already have same method for push to VC3

func showVC1() {
//any logic to call VC1 from VC2
//break point never called
}

class Controller4: UIViewController {
weak var delegate: Controller2Delegate?

func GoToVC1() {
//method who's call logic for pop to VC2
delegate?.showVC1 
}// breakpoint is called
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source