Im trying to create generic UIPageViewControlller and for that I want to use default implementation in protocol extension but Im getting this weir error
Objective-C method 'pageViewController:viewControllerBefore:' provided by method 'pageViewController(_:viewControllerBefore:)' does not match the requirement's selector ('pageViewController:viewControllerBeforeViewController:')
This is how my code looks like
protocol ViewModel {}
protocol PagerCard: class {
var viewModel: ViewModel? { get set }
}
protocol Pager: UIPageViewControllerDataSource {
associatedtype Card: UIViewController, PagerCard
associatedtype CardModel: ViewModel
var pagerController: UIPageViewController! { get set }
var cards: Array<Card> { get set }
var cardModels: Array<CardModel> { get set }
func cardFactory() -> Card
func viewControllerAtIndex(_ index: Int) -> Card?
}
extension Pager {
func viewControllerAtIndex(_ index: Int) -> Card? {
if (cardModels.count == 0) ||
(index >= cardModels.count || index < 0) {
return nil
}
// Get already configured controller
if self.cards.count > index {
return self.cards[index]
}
let cardVC = self.cardFactory()
cardVC.viewModel = cardModels[index]
cards.append(cardVC)
return cardVC
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
let index = self.cards.index(of: viewController as! Card )!
return self.viewControllerAtIndex(index - 1)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
let index = self.cards.index(of: viewController as! Card)!
return self.viewControllerAtIndex(index + 1)
}
}
Problem is in Pager extension in last two methods, xcode complains about functions declarations but they are exactly the same as in UIPageViewControllerDataSource, if I use exactly the same code in UIViewController, everything works. Any ideas?? thank you