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
FetchingView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod '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 } } } }
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) }
NeilsUltimateLab, [email protected]
FetchingView is available under the MIT license. See the LICENSE file for more info.
