     
     var lastOffset: CGFloat = 0
     func scrollViewDidScroll(scrollView: UIScrollView) {
-        
         guard let jumpIndex = jumpFromIndex else {
             return
         }

import UIKit

class InfiniteCarousel: UICollectionView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
    @IBInspectable var buffer = 3
    
    var count = 0
    

    }
    
    override func shouldUpdateFocusInContext(context: UIFocusUpdateContext) -> Bool {
        print("shouldUpdateFocusInContext: " + debugFocusChange(context))
        
        let (_, to) = self.convertToIndexPaths(context)
        guard to != nil else {
            return false
        }

        if jumpFromIndex != nil {
            if focusHeading != context.focusHeading {
                // Swapped directions mid jump -- abort
                jumpFromIndex = nil
                jumpToIndex = nil
                jumpToFocusIndex = nil
            }
        }
        
        focusHeading = context.focusHeading
        if focusHeading == .Left {
            if to!.item < 0 {
                return false
            }
            if to!.item < buffer {
                print("Going left, asking to go to \(to!.item); sending to \(buffer + count - 1); focusing on \(to!.item + count)")
                jumpFromIndex = jumpFromIndex ?? to!.item
                jumpToIndex = buffer + count - 1
                jumpToFocusIndex = to!.item + count
            }
        }
        
        if focusHeading == .Right {
            if to!.item >= 2*buffer + count {
                return false
            }
            if to!.item >= buffer + count {
                print("Going right, asking to go to \(to!.item); sending to \(buffer); focusing on \(to!.item - count)")
                jumpFromIndex = jumpFromIndex ?? to!.item
                jumpToIndex = buffer
                jumpToFocusIndex = to!.item - count
            }
        }

        return true
    }
    
    override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
        print("didUpdateFocus: " + debugFocusChange(context))
        
        super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator)
    }

    
