Instantly share code, notes, and snippets.

Embed
What would you like to do?
RAC Extension for ReactiveCocoa
import Kingfisher
import ReactiveCocoa
import enum Result.NoError
extension KingfisherManager {
func rac_retrieveImageWithURL(URL: NSURL,
optionsInfo: KingfisherOptionsInfo?,
progressBlock: DownloadProgressBlock?) -> SignalProducer<(image: UIImage?, cacheType: CacheType, imageURL: NSURL?), NSError> {
return SignalProducer { observer, disposable in
let imageTask = KingfisherManager.sharedManager.retrieveImageWithURL(URL, optionsInfo: optionsInfo, progressBlock: progressBlock) { (image, error, cacheType, imageURL) -> () in
if let error = error {
observer.sendFailed(error)
} else {
observer.sendNext(image: image, cacheType: cacheType, imageURL: imageURL)
observer.sendCompleted()
}
}
disposable.addDisposable {
imageTask.cancel()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment