ios - How do I change the initial tab bar selection in swift? -


in trying find solution came across answer:

[ https://stackoverflow.com/a/10441200/4856759 ]

it seems accomplish want to, in objective c:

uitabbarcontroller *tabbar = (uitabbarcontroller *)self.window.rootviewcontroller; tabbar.selectedindex = 0; 

how do in swift? first attempt returns error:

cannot convert expression's type '$t4??' type 'uitabbarcontroller'

var tabbar: uitabbarcontroller = self.window?.rootviewcontroller tabbar.selectedindex = 1 

worked me! need add as! uitabbarcontroller:

var tabbar: uitabbarcontroller = self.window?.rootviewcontroller as! uitabbarcontroller tabbar.selectedindex = 1 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -