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

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -