title: To access tabbar from uiview in swift
body: <p>In my application when I am getting any notification I am showing a customView. And if user touches anywhere on the screen, the view will disappear. I have a <code>UITabBar</code> with four tabs. After getting notification, when I click on the view, the 2nd tab should be selected (I may be anywhere in the app). But I am unable to select the 2nd tab. It always opens the first tab. How do I call the "didSelect item" from this customView? Following is my code. Please verify it and help me to resolve my issue.</p>
  
  <p><strong>My code is:</strong></p>
  
  <pre><code>{
      let storyBoard = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MainTabbarView") as? MainTabbarView
      storyBoard?.selectItem(withIndex: 3)  
  } 
  </code></pre>
  
  <p><strong>In my UITabBarController I have wrritten the following code:</strong></p>
  
  <pre><code>func selectItem(withIndex index: Int) {
      if let controller = tabBarController, let tabBar = tabBarController?.tabBar, let items = tabBarController?.tabBar.items {
          guard index &lt; items.count else { return }
          controller.selectedIndex = index
          controller.tabBar(tabBar, didSelect: items[index])
      }
  } 
  
  override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
      if let items = tabBar.items {
          items.enumerated().forEach { if $1 == item { print("your index is: \($0)") } }
      }
  }
  </code></pre>