Skip to content

NeilsUltimateLab/FetchingView

Repository files navigation

FetchingView

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Fetching view has a state machine called Fetching State :

enum FetchingState<A> {
    case fetching
    case fetchedError(AppErrorProvider)
    case fetchedData(A)
}

Fetching view will display UIActivityIndicatorView for FetchingState<A>.fetching and error message for .fetchedError(Error) state.

#####Here is an screenshot from an example application using FetchingView

Screenshot of Example application

Requirements

Installation

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

pod 'FetchingView'

Usage

How to use FetchingView?

import UIKit
import FetchingView

class ViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!
    var fetchingView: FetchingView<[User]>!

    func viewDidLoad() {
        super.viewDidLoad()
        ...
        self.fetchingView = FetchingView(listView: tableView, parentView: self.view)
    }

    func fetchResource() {
        self.fetchingView.fetchingState = .fetching
        User.fetchResource { result in
            if let error = result.error {
                self.fetchingView.fetchingState = .fetchedError(error)
            }
            if let users = result.value {
                self.fetchingView.fetchingState = .fetchedData(users)
                //update dataSource and reloadData
            }
        }
    }

}

How to show HUD?

func showHUD() {
    self.fetchingView.showHUD()
    // task
    self.fetchingView.hideHUD()
}

func showMessageHUD() {
    self.fetchingView.showHUD(title: nil, message: "Your request is submitted successfully.", delay: 2.0)
}

Author

NeilsUltimateLab, [email protected]

License

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