title: IOS Swift Open View Controller Programmatically
body: <p>can you help me what is the best/proper way to launch ViewControllers programmatically?</p>
  
  <p>For example, </p>
  
  <ul>
  <li><p>I have a <code>LoginViewController</code>, a <code>ListViewController</code>, and an <code>ItemViewController</code>. </p></li>
  <li><p><code>LoginViewController</code> is launched first then it verifies the token/account through an API asynchronously. </p></li>
  <li><p>After it is verified, it will go to <code>ListViewController</code>. </p></li>
  </ul>
  
  <p>What I want to do is, for example the app is opened through <code>UIApplicationOpenURLOptionsKey</code> or <code>launchedwithRemoteNotification</code>, I would open <code>ItemViewController</code> programatically.</p>
  
  <p>I can do this by showing a <code>viewcontroller</code> in </p>
  
  <pre><code>let currentView = self.window?.rootViewController?.presentedViewController
  </code></pre>
  
  <p>then present the view from it. However, i think <code>presentedViewController</code> is <code>nil</code> when the app is opened on the first time. I can make some work arounds, but is there a more proper or standard way to handle this?</p>
  
  <p>Thanks!</p>