title: tab bar did select delegate methods give the previously selected tab index in ios, swift 3
body: <p>I'm trying to detect which tab selected by the user, realtime. as an example, if user selecte <code>0 th</code> index, at the same time I want to get that user has selected the <code>zeroth</code> index tab. so for that , I used <code>tabbarcontroller</code> delegate method like below.</p>
  
  <pre><code>override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
  
          print("the selected index is : \(selectedIndex)")
      }
  </code></pre>
  
  <p>but this shows the previous view controller.as an example think I'm in <code>second tab</code> and then I select the <code>first tab</code> then this prints the index as <code>2</code>.so how can I get the correct selected tab.
  hope your help with this.</p>