We need to pass the object we are testing to the UIViewController , since we know that the array from controllers contains the UIViewController (and we know that the UIViewController matches Equatable .
extension PageViewController : UIPageViewControllerDelegate { func pageViewController(pageViewController: UIPageViewController, willTransitionToViewControllers pendingViewControllers: [AnyObject]) { if let controller = pendingViewControllers.first as? UIViewController { self.nextIndex = self.viewControllers.indexOf(controller) } } }
The logic of the error is that in order for the indexOf method indexOf compare the object that you passed, it must compare them using the == operator. The Equatable protocol indicates that the class has implemented this function, therefore it is that indexOf requires matching its arguments.
Objective-C does not have the same requirement, but the actual implementation of Objective-C ends up comparing the argument with the objects in the array using the isEqual: method (which NSObject and therefore all Objective-C implement classes).
source share