I have this objective-c method that i'm trying to re-write to swift.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
int index = [navigationController.viewControllers indexOfObject:viewController];
self.pageControl.currentPage = index;
}
I'm having difficulties writing this line in swift:
int index = [navigationController.viewControllers indexOfObject:viewController];
How do i access the IndexOfObject?
In Swift 1.2 (Xcode 6.x)
let index = find(navigationController.viewControllers, viewController)!
In Swift 2.0 (Xcode 7.x)
let arrayOfVCs = navigationController.viewControllers as Array
let index = arrayOfVCs.indexOf(viewController)