 
 extension ViewPager:UIScrollViewDelegate{
     
-    //http://stackoverflow.com/a/1857162
-    public func scrollViewDidScroll(scrollView: UIScrollView) {
-        NSObject.cancelPreviousPerformRequestsWithTarget(scrollView)
-        self.performSelector(#selector(self.scrollViewDidEndScrollingAnimation(_:)), withObject: scrollView, afterDelay: 0.3)
-    }
-    
-    public func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
-        NSObject.cancelPreviousPerformRequestsWithTarget(self)
+    public func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
+        NSObject.cancelPreviousPerformRequests(withTarget: self)
         var pageNumber = round(scrollView.contentOffset.x / scrollView.frame.size.width)
         pageNumber = pageNumber + 1
         pageControl.currentPage = Int(pageNumber)
         currentPosition = pageControl.currentPage
-        scrollToPage(Int(pageNumber))
-    }
-    
+        scrollToPage(index: Int(pageNumber))
+    }
+    
+    //http://stackoverflow.com/a/1857162
+    public func scrollViewDidScroll(_ scrollView: UIScrollView) {
+        NSObject.cancelPreviousPerformRequests(withTarget: scrollView)
+        self.perform(#selector(self.scrollViewDidEndScrollingAnimation(_:)), with: scrollView, afterDelay: 0.3)
+    }
     
 }
 

    
    
    func animationNext(){
        NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector: #selector(ViewPager.moveToNextPage), userInfo: nil, repeats: true)
    }
    func moveToNextPage (){
        if(currentPosition <= numberOfItems && currentPosition > 0) {
            scrollToPage(currentPosition)
            currentPosition = currentPosition + 1
            if currentPosition > numberOfItems {
                currentPosition = 1

@objc public protocol  ViewPagerDataSource {
    func numberOfItems(viewPager:ViewPager) -> Int
    func viewAtIndex(viewPager:ViewPager, index:Int, view:UIView?) -> UIView
    @objc optional func didSelectedItem(index:Int)
    
}

