title: How to use protocol and delegate in my class?
body: <p>I am using two view Controllers i.e. StateListVC and PlayVC. In StateListVC, I am using container view with 3 VCs. After tapping on 3rd View Controller, I am going to PlayVC with delegate method. I don't know how to do that. Please help me to resolve this issue.</p>
  
  <p>StateListVC</p>
  
  <pre><code>class StateListVC: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
      }
  
      override func viewWillAppear(_ animated: Bool) {
          if isMoveToAnotherVC
          {
              let vc = self.storyboard?.instantiateViewController(withIdentifier: "PlaceVC") as! PlaceVC
              vc.delegate = self
          }
  
      }
  }
  
  extension StateListVC: MoveToAnotherVC {
      func moving(string: String) {
          print(string)
      }
  }
  </code></pre>
  
  <p>ThirdVC</p>
  
  <pre><code>protocol MoveToAnotherVC {
      func moving(string: String)
  }
  
  class PlaceVC: UIViewController {
  
      @IBOutlet weak var tableViewPlace: UITableView!
      var delegate: MoveToAnotherVC? = nil
  
      var arrPlace = ["Place1", "Place2"]
  
      override func viewDidLoad() {
          super.viewDidLoad()
      }
  
  extension PlaceVC: UITableViewDataSource {
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return arrPlace.count
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
          cell.textLabel?.text = arrPlace[indexPath.row]
          return cell
      }
  }
  
  extension PlaceVC: UITableViewDelegate {
      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
      {
          isMoveToAnotherVC = true
  
          print(delegate)
          guard let delegate = self.delegate else{
              print("Delegate not set")
              return
          }
  
          delegate.moving(string: "test")
      }
  }
  </code></pre>