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 andisEmpty
is true
To run the example project, clone the repo, and run pod install
from the Example directory first.
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?
let URLRequest = NSURLRequest(URL: NSURL(string: "http://httpbin.org/status/400")!)
NSURLSession.sharedSession().rx_data(URLRequest).attachToDataRequestView(dataRequestView!).subscribe()
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!)
ALDataRequestView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ALDataRequestView"
Antoine van der Lee, [email protected]
ALDataRequestView is available under the MIT license. See the LICENSE file for more info.