         tableView.infiniteScrollIndicatorMargin = 40
         
         // Add infinite scroll handler
-        tableView.addInfiniteScrollWithHandler { [weak self] (scrollView: AnyObject!) -> Void in
-            let scrollView = scrollView as! UIScrollView
+        tableView.addInfiniteScrollWithHandler { [weak self] (scrollView) -> Void in
+            let scrollView = scrollView as! UITableView
             
             self?.fetchData() {
                 scrollView.finishInfiniteScroll()

    private let JSONResultsKey = "hits"
    private let JSONNumPagesKey = "nbPages"
    
    var currentPage = 0
    var numPages = 0
    var stories: Array<StoryModel> = []
    
    override func viewDidLoad() {
        super.viewDidLoad()

        })
    }
    
    private func handleResponse(data: NSData!, response: NSURLResponse!, error: NSError!) {
        if error != nil {
            showAlertWithError(error)
            return;
        }
        
        var jsonError: NSError?
        let responseDict = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.allZeros, error: &jsonError) as? Dictionary<String, AnyObject>
        
        if jsonError != nil {
            showAlertWithError(jsonError)
            return
        }
        
        if let pages = responseDict?[JSONNumPagesKey] as? NSNumber {
            numPages = pages as! Int
        }
        
        if let results = responseDict?[JSONResultsKey] as? Array<Dictionary<String, AnyObject>> {
            currentPage++

            for i in results {
                stories.append(StoryModel(i))
            }
            
            tableView.reloadData()
        }
    }
    
    private func showAlertWithError(error: NSError!) {
        let alert = UIAlertView(
            title: NSLocalizedString("Error fetching data", comment: ""),
            message: error.localizedDescription,
            delegate: self,
            cancelButtonTitle: NSLocalizedString("Dismiss", comment: ""),
            otherButtonTitles: NSLocalizedString("Retry", comment: "")
        )
        alert.show()
    }

}
