i used to say in obj-c
[self.tabBarController.viewControllers objectAtIndex:1];
but now in swift no ObjectAtIndex any more
self.tabBarController.viewControllers.ObjectAtIndex
Update
ok i am gonna make it simple lets consider i have tabBarController it contains 2 object [FirstViewController,SecondViewController] and i am trying to make a delegate between the object here is the code to set the delegate
var Svc:SecondViewController = self.tabBarController.viewControllers[1] as SecondViewController!
Svc.delegate = self
when i Run , i got this error 0x1064de80d: movq %r14, %rax and no console error is showing up
Your code is OK:
... however you can omit
!
mark at the end and:SecondViewController
type definition since it can be inferred by the cast:The problem appears because you try to cast to the wrong class. Try to print to debug log name of the class of object at
[1]
; add this before your cast to check the class name:UPDATE:
As we figured out in comments, you should cast received view controller to
UINavigationController
:Later you can examine
nc.viewControllers
property and see if for instance itstopViewController
isSecondViewController
:You don't need
objectAtIndex
in swift, just use thesubscript
operator: