swift - Could not cast value of type UITabBarController to FirstViewController (xCode 6.4) -


i'm trying pass variables view controller one. first, there's connection screen. when infos verified, pass username , other data whole program (that has tab bar controller).

here code. i'm using xcode 6.4. in previous version, page open variables didn't pass. gives me above error.

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {         if (segue.identifier == "lienconnecte") {             let nav = segue.destinationviewcontroller as! uitabbarcontroller // line attempt find solution             let vuefil = segue.destinationviewcontroller as! firstviewcontroller              vuefil.utilisateur = utilisateur          }     } 

of course know in storyboard, segue points tab bar controller (because need afterwards), want values passed firstcontrollerview

found solution, see post:

let tabbarcontroller = segue.destinationviewcontroller as! uitabbarcontroller let vuefil = tabbarcontroller.viewcontrollers![0] as! firstviewcontroller 

you cannot turn 1 thing another, sort of magician, saying as. have reference actual thing you're after. if there's firstviewcontroller 1 of child view controllers of uitabbarcontroller, first reference uitabbarcontroller (which know how do), , obtain viewcontrollers property — children, , can, there, 1 want index number.


Comments