title: Prevent to create multiple instances from same type ViewController (ARC)
body: <p>I am working with <code>UINavigationController</code>. 
  I want to prevent to create multiple instances from same type ViewController. 
  If I have a <code>UINavigationController</code> with four children ViewController(s) <strong>(A, B, C, D)</strong> and another ViewController (<strong>E</strong>) and I navigate from <code>A -&gt; B -&gt; C -&gt; D</code> and in <strong>D</strong>ViewController I will instantiate  <strong>E</strong>ViewController and I will present it .. and from <strong>E</strong>ViewController I go to <strong>A</strong> ViewController I will have 2 instances from <strong>A</strong>ViewController .. and I want to prevent it.</p>
  
  <p>Here is storyboard with all ViewController(s):
  <a href="https://i.stack.imgur.com/OYHI6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OYHI6.png" alt="enter image description here"></a></p>
  
  <p>How I navigate from <strong>D</strong> to <strong>E</strong>:</p>
  
  <pre><code>let vc = self.storyboard?.instantiateViewController(withIdentifier: "E") as? E   
  self.present(vc!, animated: true)
  </code></pre>
  
  <p>How I navigate from <strong>E</strong> to <strong>A</strong>: </p>
  
  <pre><code>self.performSegue(withIdentifier: "aSegue", sender: nil)
  </code></pre>
  
  <p>I found some solutions as:</p>
  
  <p>1) When I am in <strong>E</strong> ViewController should destory all ViewController(s) (<strong>A, B, C, D</strong>)</p>
  
  <p>2) When I navigate from <strong>E</strong> to <strong>A</strong> .. check if exists <strong>A</strong>ViewController .. if it exists set as <code>rootViewController</code>, else create it and present it:</p>
  
  <pre><code>let appDelegate = UIApplication.shared.delegate as! AppDelegate
  var aVC: AViewController?
  if let viewControllers = appDelegate.window?.rootViewController?.childViewControllers {
    for vc in viewControllers {
      print(vc.debugDescription)
      if vc.isKind(of: AViewController.self) {
        aVC = vc as! AViewController
        break
      }
    }
  }
  
  
  if let vc = aVC {
    let navigation = UINavigationController(rootViewController: vc)
    AppDelegate.delegate().setRootViewController(view: navigation)
  } else {
      let vc = self.storyboard?.instantiateViewController(withIdentifier: "AViewController") as? AViewController
      self.present(vc!, animated: true)
  }
  </code></pre>
  
  <p>3) Create singleton manager for each ViewController (example: <a href="https://stackoverflow.com/a/46467132/4062046">link</a>)</p>
  
  <pre><code>class AManager {
       static let sharedInstance = AManager()
  }
  </code></pre>
  
  <p>Hope you understand my problem.
  Looking for a good solution.
  Thanks in Advance.</p>