LoadingRetry 1.0.2

LoadingRetry 1.0.2

srv7维护。



  • srv7

LoadingRetry

CI Status Version License Platform

示例

要运行示例项目,请克隆仓库,然后从Example目录运行pod install

需求

iOS 9.0+
swift 4.2+

用法

  1. 遵循LoadingRetryType协议。例如:

    class ViewController: UIViewController, LoadingRetryType {
    
    }
  2. 实现LoadingRetryType协议的要求,提供你的loadingViewerrorView viewControllerType.

    class ViewController: UIViewController, LoadingRetryType {
        lazy var loadingView: LoadingViewController = {
            return LoadingViewController()
        }()
    
        lazy var errorView: ErrorViewController = {
            return ErrorViewController()
        }()
    }
  3. 调用setLoadingView(visible: Bool)setErrorView(visible: Bool)来控制loadingViewerrorView的显示。

    viewController.setLoadingView(visible: visible)
    viewController.setErrorView(visible: visible)

安装

LoadingRetry可以通过CocoaPods获得。要安装它,只需在Podfile中添加以下行:

pod 'LoadingRetry'

Rx 支持功能

pod 'LoadingRetry/RxSwift'

代码块 `LoadingRetry` 亦增加了 Rx 支持。如果您正在使用 RxSwift,您可以通过 `UIViewController` 的扩展属性 `loadingViewVisible` 和 `errorViewVisible` 来控制 `loadingView` 和 `errorView` 的显示。

viewModel.fetchDataAction.executing.bind(to: rx.loadingViewVisible).disposed(by: bag)

viewModel.fetchDataAction.executing
            .filter { $0 }.map { !$0 }
            .bind(to: rx.errorViewVisible)
            .disposed(by: bag)

        viewModel.fetchDataAction.errors
            .map { _ in true }
            .bind(to: rx.errorViewVisible)
            .disposed(by: bag)

作者

srv7, [email protected]

许可证

LOADINGRetry 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。