title: Programmatically switching between tabs within Swift
body: <p>I need write some code to switch the view to another tab when the iOS app starts (so, for example, the second tab is shown by default rather than the first).</p>
  
  <p>I'm new to Swift, and have worked out the following:</p>
  
  <ul>
  <li><p>The code should probably go in the override func viewDidLoad() function of the ViewController of the first tab.</p></li>
  <li><p>The following code shows the second ViewController, but not with the tab bar at the bottom (vcOptions is the second ViewController tab item:</p></li>
  </ul>
  
  <pre class="lang-Objective-C prettyprint-override"><code>let vc : AnyObject! = self.storyboard.instantiateViewControllerWithIdentifier("vcOptions")
  self.showViewController(vc as UIViewController, sender: vc)
  </code></pre>
  
  <p>I think the answer may lie in using the UITabbarController.selectedIndex = 1, but not quite sure how to implement this.</p>