I need to show 3 items in a UICollectionView, with paging enabled like this

Mine solution to horizontal collection view paging
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if scrollView == collectionView { collectionView.scrollToPage() }
}
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if scrollView == collectionView { if !decelerate { collectionView.scrollToPage() } }
}
And small extension to collectionView
public func scrollToPage() {
var currentCellOffset = contentOffset
currentCellOffset.x += width / 2
var path = indexPathForItem(at: currentCellOffset)
if path.isNil {
currentCellOffset.x += 15
path = indexPathForItem(at: currentCellOffset)
}
if path != nil {
logInfo("Scrolling to page \(path!)")
scrollToItem(at: path!, at: .centeredHorizontally, animated: true)
}
}