title: how to set variables on back press in navigationController swift?
body: <p>According to <a href="https://stackoverflow.com/a/34956946/4646999">this link</a> , I wanted to pass some data from a B <code>viewController</code> to its parent, A <code>viewController</code>, on back press! here is my code :
  in my B <code>viewController</code>, I've added this code -</p>
  
  <pre><code>    extension Bcontroller: UINavigationControllerDelegate {
      func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
  
          (viewController as? Acontroller)?.number = numberInB
          (viewController as? Acontroller)?.myBoolean = boolInB
  
      }
  }
  </code></pre>
  
  <p>and here is my code in A controller :</p>
  
  <pre><code>override func viewWillAppear(_ animated: Bool) {
      if number != -1 {
          print(myBoolean)
      }
  }
  </code></pre>
  
  <p>when I open B controller, <code>navigationController (willShow)</code> is called, and when I press back button, <code>viewWillAppear</code> is called first, and then <code>navigationController(willShow)</code> in B controller is called! so my data is not set, and  <code>number</code> will be always <code>-1</code> . how can I set these variable?</p>