Skip to content

A view representation for data requests. Support for ReactiveCocoa and RXSwift

License

Notifications You must be signed in to change notification settings

Jeroenbb94/ALDataRequestView

 
 

Repository files navigation

ALDataRequestView

Version License Platform

A simple way to show:

  • Loading view while a producer or observable is started
  • Reload view when a producer or observable is failed
  • Empty view when a producer or observable returns an empty array or an object which inherits the Emptyable protocol and isEmpty is true

Usage

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

ReactiveCocoa & RxSwift

Simply call

attachToDataRequestView(dataRequestView)

on your signalProducer or observable.

Make sure you implement the ALDataRequestViewDataSource:

func loadingViewForDataRequestView(dataRequestView: ALDataRequestView) -> UIView?
func reloadViewControllerForDataRequestView(dataRequestView: ALDataRequestView) -> ALDataReloadType?
func emptyViewForDataRequestView(dataRequestView: ALDataRequestView) -> UIView?

Examples

RxSwift
let URLRequest = NSURLRequest(URL: NSURL(string: "http://httpbin.org/status/400")!)
NSURLSession.sharedSession().rx_data(URLRequest).attachToDataRequestView(dataRequestView!).subscribe()
ReactiveCocoa
let URLRequest = NSURLRequest(URL: NSURL(string: "http://httpbin.org/status/400")!)
NSURLSession.sharedSession()
    .rac_dataWithRequest(URLRequest)
    .flatMap(.Latest, transform: { (data, response) -> SignalProducer<NSData, NSError> in
        if let httpResponse = response as? NSHTTPURLResponse where httpResponse.statusCode > 299 {
            return SignalProducer(error: NSError(domain: "", code: httpResponse.statusCode, userInfo: nil))
        }
        return SignalProducer(value: data)
    })
    .attachToDataRequestView(dataRequestView!)

Installation

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

pod "ALDataRequestView"

Author

Antoine van der Lee, [email protected]

License

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

About

A view representation for data requests. Support for ReactiveCocoa and RXSwift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 90.4%
  • Ruby 9.6%