Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save srfunksensei/7943d156f9b13772e4477d2bc56f99ad to your computer and use it in GitHub Desktop.

Select an option

Save srfunksensei/7943d156f9b13772e4477d2bc56f99ad to your computer and use it in GitHub Desktop.
CarouselSample
// MARK: - DataSource
extension CarouselPageViewController: UIPageViewControllerDataSource {
func pageViewController(_: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = items.index(of: viewController) else {
return nil
}
let previousIndex = viewControllerIndex - 1
guard previousIndex >= 0 else {
return items.last
}
guard items.count > previousIndex else {
return nil
}
return items[previousIndex]
}
func pageViewController(_: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = items.index(of: viewController) else {
return nil
}
let nextIndex = viewControllerIndex + 1
guard items.count != nextIndex else {
return items.first
}
guard items.count > nextIndex else {
return nil
}
return items[nextIndex]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment