Getting a value in ViewController from AppDelegate : <p>I am trying to get the value in ViewController from AppDelegate, but I am not able to do so. </p>

<p>I have only one ViewController. I tried to make the value as a constant or variable. None of them works. </p>

<p>I am not sure if this is the correct approach, but I tried to use rootViewController to access. </p>

<pre><code>class ViewController: UIViewController {
  override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    var test:String = "test"   
  // let test = "test" 
  }
}
</code></pre>

<p>in AppDelegate</p>

<pre><code>  func application(_ application: UIApplication, 
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {

    let viewController = self.window?.rootViewController as? ViewController
    print("from_viewC \(String(describing: viewController?.test)))")
}
</code></pre>
