<commit_before># KissPaginate

[![CI Status](http://img.shields.io/travis/WANGjieJacques/KissPaginate.svg?style=flat)](https://travis-ci.org/WANGjieJacques/KissPaginate)
[![Version](https://img.shields.io/cocoapods/v/KissPaginate.svg?style=flat)](http://cocoapods.org/pods/KissPaginate)
[![License](https://img.shields.io/cocoapods/l/KissPaginate.svg?style=flat)](http://cocoapods.org/pods/KissPaginate)
[![Platform](https://img.shields.io/cocoapods/p/KissPaginate.svg?style=flat)](http://cocoapods.org/pods/KissPaginate)
[![codecov](https://codecov.io/gh/WANGjieJacques/KissPaginate/branch/master/graph/badge.svg)](https://codecov.io/gh/WANGjieJacques/KissPaginate)

## Example

To run the example project, clone the repo, and run `pod install` from the Example directory first.
### Inherit from PaginateViewController
```swift
class ViewController: PaginateViewController {
    @IBOutlet weak var noElementLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.dataSource = self
        /// refresh the elements
        refreshElements()
    }

    override var getElementsClosure: (page: Int, successHandler: GetElementsSuccessHandler, failureHandler: (error: NSError) -> Void) -> Void {
        return getElementList
    }

    func getElementList(page: Int, successHandler: GetElementsSuccessHandler, failureHandler: (error: NSError) -> Void) {
        let elements = (0...20).map { "page \(page), element index" + String($0) }
        /// web service mock.
        delay(2) {
            successHandler(elements: elements, hasMoreElements: true)
        }
    }

    override func displayNoElementIfNeeded(noElement: Bool) {
        noElementLabel.hidden = !noElement
    }
}

extension ViewController: UITableViewDataSource {
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return elements.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell")!
        let element = getElement(String.self, at: indexPath.row)
        cell.textLabel?.text = element
        if elements.count == indexPath.row + 1 {
            /// load the next page here.
            loadNextPage()
        }
        return cell
    }
}
```

### Inherit from PaginateView

if your ViewController already has a parent class, you can inherit from the protocal `PaginateView`

```swift
class ViewController: UIViewController, PaginateView {

    var presenter: PaginatePresenter!
    var refreshControl: UIRefreshControl!
    var bottomRefresh: UIActivityIndicatorView!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var noElementLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        presenter = PaginatePresenter(paginatable: self)
        presenter.start()
        tableView.dataSource = self
        refreshElements()
    }

    var getElementsClosure: (page: Int, successHandler: GetElementsSuccessHandler, failureHandler: (error: NSError) -> Void) -> Void {
        return getElementList
    }

    func getElementList(page: Int, successHandler: GetElementsSuccessHandler, failureHandler: (error: NSError) -> Void) {
        let elements = (0...20).map { "page \(page), element index" + String($0) }
        delay(2) {
            successHandler(elements: elements, hasMoreElements: true)
        }
    }

    func displayNoElementIfNeeded(noElement: Bool) {
        noElementLabel.hidden = !noElement
    }
}

extension ViewController: UITableViewDataSource {
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return elements.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell")!
        let element = getElement(String.self, at: indexPath.row)
        cell.textLabel?.text = element
        if elements.count == indexPath.row + 1 {
            loadNextPage()
        }
        return cell
    }
}
```
## Requirements

## Installation

KissPaginate is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod 'KissPaginate'
```

## Author

<NAME>, <EMAIL>
<commit_msg>Update readme to swift 3.0<commit_after># KissPaginate

[![CI Status](http://img.shields.io/travis/WANGjieJacques/KissPaginate.svg?style=flat)](https://travis-ci.org/WANGjieJacques/KissPaginate)
[![Version](https://img.shields.io/cocoapods/v/KissPaginate.svg?style=flat)](http://cocoapods.org/pods/KissPaginate)
[![License](https://img.shields.io/cocoapods/l/KissPaginate.svg?style=flat)](http://cocoapods.org/pods/KissPaginate)
[![Platform](https://img.shields.io/cocoapods/p/KissPaginate.svg?style=flat)](http://cocoapods.org/pods/KissPaginate)
[![codecov](https://codecov.io/gh/WANGjieJacques/KissPaginate/branch/master/graph/badge.svg)](https://codecov.io/gh/WANGjieJacques/KissPaginate)

## Example

To run the example project, clone the repo, and run `pod install` from the Example directory first.
### Inherit from PaginateViewController
```swift
class ViewController: PaginateViewController {

    @IBOutlet weak var noElementLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.dataSource = self
        refreshElements()
    }

    override var getElementsClosure: (_ page: Int, _ successHandler: @escaping GetElementsSuccessHandler, _ failureHandler: @escaping (NSError) -> Void) -> Void {
        return getElementList
    }

    func getElementList(_ page: Int, successHandler: @escaping GetElementsSuccessHandler, failureHandler: (_ error: NSError) -> Void) {
        let elements = (0...20).map { "page \(page), element index" + String($0) }
        delay(2) {
            successHandler(elements, true)
        }
    }

    override func displayNoElementIfNeeded(noElement: Bool) {
        noElementLabel.isHidden = !noElement
    }
}

extension ViewController: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return elements.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
        let element = getElement(String.self, at: (indexPath as NSIndexPath).row)
        cell.textLabel?.text = element
        if elements.count == (indexPath as NSIndexPath).row + 1 {
            loadNextPage()
        }
        return cell
    }
}
```

### Inherit from PaginateView

if your ViewController already has a parent class, you can inherit from the protocal `PaginateView`

```swift  
class PaginateView: UIViewController, PaginateView {

    var presenter: PaginatePresenter!
    var refreshControl: UIRefreshControl!
    var bottomRefresh: UIActivityIndicatorView!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var noElementLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        presenter = PaginatePresenter(paginatable: self)
        presenter.start()
        tableView.dataSource = self
        refreshElements()
    }

    var getElementsClosure: (_ page: Int, _ successHandler: @escaping GetElementsSuccessHandler, _ failureHandler: @escaping (NSError) -> Void) -> Void {
        return getElementList
    }

    func getElementList(page: Int, successHandler: @escaping GetElementsSuccessHandler, failureHandler: @escaping (NSError) -> Void) {
        let elements = (0...20).map { "page \(page), element index" + String($0) }
        delay(2) {
            successHandler(elements, true)
        }
    }

    func displayNoElementIfNeeded(noElement: Bool) {
        noElementLabel.isHidden = !noElement
    }
}

extension PaginateView: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return elements.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
        let element = getElement(String.self, at: (indexPath as NSIndexPath).row)
        cell.textLabel?.text = element
        if elements.count == (indexPath as NSIndexPath).row + 1 {
            loadNextPage()
        }
        return cell
    }
}

```
## Requirements

## Installation

KissPaginate is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod 'KissPaginate'
```

## Author

<NAME>, <EMAIL>

{'fraction_non_alphanumeric': 0.11164383561643836, 'fraction_numerical': 0.0029680365296803654, 'mean_word_length': 3.51365275631118, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2572453', 'n_tokens_mistral': 2776, 'n_tokens_neox': 2630, 'n_words': 582}