in ScrollingFeed/Controllers/StreamsViewController.swift [70:81]
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let nextStreamVC = storyboard?.instantiateViewController(withIdentifier: "StreamViewController") as? StreamViewController,
let vc = viewController as? StreamViewController,
let stream = vc.stream else {
return nil
}
let currentIndex = streams.firstIndex(where: { $0.id == stream.id }) ?? 0
let index = currentIndex == streams.count - 1 ? 0 : currentIndex + 1
nextStreamVC.setup(streams[index], delegate: self)
return nextStreamVC
}