Latest 1.2.3
Homepage https://github.com/congncif/PagingDataController
License MIT
Platforms ios 8.0
Authors

Version
License
Platform

Screenshot
Pull to refresh
Load more data next page

If you find it difficult or uncomfortable when having to write the code again while working with data paging, PagingDataController framework is a solution for you. It’s simple and extremely easy to use. Let me help you get started:

Requirements

  • XCode 8+
  • Swift 3+
  • iOS 8+

Installation

PagingDataController is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'PagingDataControllerExtension'

Author

NGUYEN CHI CONG, [email protected]

License

PagingDataController is available under the MIT license. See the LICENSE file for more info.

Getting started

Provider: provider is a controller, it will retrieve data by page number
  • Creating a provider.
  • Implement loadData method

    struct GithubUsersProvider: PagingProviderProtocol {
    
    //custom pageSize here
    var pageSize: Int = 36
    
    /*******************************************************************************************************
     * Replace type of Parameters and Return model by custom type in your app
     * Example:
     * func loadData(_ parameters: <#ParamterType#>?, page: Int, completion: (([<#ReturnType#>], Error?) -> ())?)
     *******************************************************************************************************/
    
    func loadData(_ parameters: AnyObject?, page: Int, completion: (([Dictionary<String, AnyObject>], Error?) -> ())?) {
    
        let apiPath = "https://api.github.com/search/users?q=apple&page=(page+1)&per_page=(pageSize)"
        Alamofire.request(apiPath, method: .get).responseJSON { (response) in
            var error: Error? = response.result.error
            var result: [[String: AnyObject]] = []
    
            defer {
                completion?(result, error)
            }
    
            guard let data = (response.result.value as? [String: AnyObject]) else {
                return
            }
            result = data["items"] as! [[String: AnyObject]]
        }
    }
    }
    Implement view controller conform PagingControllerProtocol protocol
class GithubUsersViewController: UIViewController , PagingControllerProtocol {
[...]
}
  • Declare provider to get data by page. Replace provider by your provider.
    lazy var provider = GithubUsersProvider()
  • Setup for paging data. All you have to do is copying the below method into your view controller.

    /******************************************
     Copy this method into your view controller
    ******************************************/
    override func viewDidFinishLayout() {
        super.viewDidFinishLayout()
        setupForPaging()
    }
  • All done. Too easy, right?. Good luck!

Latest podspec

{
    "name": "PagingDataController",
    "version": "1.2.3",
    "summary": "A Swift pattern to apply paging data to UIViewController",
    "description": "Only configure some properties & your view controller will load data by page automatically.nMagic !!!",
    "homepage": "https://github.com/congncif/PagingDataController",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "NGUYEN CHI CONG": "[email protected]"
    },
    "source": {
        "git": "https://github.com/congncif/PagingDataController.git",
        "tag": "1.2.3"
    },
    "social_media_url": "https://twitter.com/congncif",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "PagingDataController/Classes/**/*"
}

Pin It on Pinterest

Share This