title: Swift/iOS13 - UIApplication.shared.delegate.window?.rootViewController?.present() from custom class
body: <p>I created a new <strong>Storyboard project</strong> in Xcode11 and trying to present a ViewController from <strong>custom class</strong> like this(which works just fine in older project): </p>
  
  <pre><code>let appDelegate = UIApplication.shared.delegate as! AppDelegate
  let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
  let vc : UIViewController = storyboard.instantiateViewController(withIdentifier: "NotificationVC") as UIViewController
  appDelegate.window?.makeKeyAndVisible()
  appDelegate.window?.rootViewController?.present(vc, animated: true, completion: nil)
  </code></pre>
  
  <p>Of course this doesn't work now because there is no window variable in AppDelegate anymore which has been moved to the SceneDelegate. </p>
  
  <p><strong>Error:</strong> <code>Value of type 'AppDelegate' has no member 'window'</code></p>
  
  <p>How would you make this code work now? </p>
  
  <p><strong>What I'm trying to do:</strong></p>
  
  <p>I'm trying to show a ViewController when user taps/clicks on the Push Notification Tray.</p>
  
  <p><strong>EDIT:</strong> For now I was able to make it work by creating a private static variable in SceneDelegate, and accessing that variable in my custom class:</p>
  
  <p><strong>SceneDelegate.swift</strong></p>
  
  <pre><code>private(set) static var shared: SceneDelegate?
  func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
  
      guard let _ = (scene as? UIWindowScene) else { return }
      Self.shared = self
  }
  </code></pre>
  
  <p><strong>CustomClass.swift</strong></p>
  
  <pre><code>let sceneDeleage = SceneDelegate.shared
  let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
  let vc : UIViewController = storyboard.instantiateViewController(withIdentifier: "NotificationVC") as UIViewController
  sceneDeleage?.window?.makeKeyAndVisible()
  sceneDeleage?.window?.rootViewController?.present(vc, animated: true, completion: nil)
  </code></pre>
  
  <p>Which is probably not recommended as stated here: <a href="https://stackoverflow.com/a/58547992/9511942">https://stackoverflow.com/a/58547992/9511942</a>, but it works</p>
  
  <p><strong>EDIT2:</strong> Here is my another solution thanks to <a href="https://stackoverflow.com/a/58557634/9511942">https://stackoverflow.com/a/58557634/9511942</a></p>
  
  <pre><code>    let window = UIApplication.shared.windows.first
      let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
      let vc : UIViewController = storyboard.instantiateViewController(withIdentifier: "NotificationVC") as UIViewController
      window?.makeKeyAndVisible()
      window?.rootViewController = vc
  </code></pre>
  
  <p>If someone finds a better solution, please share.</p>