Created
May 8, 2016 18:56
-
-
Save AvdLee/efd86277eeeabb8d56f88097e6af043f to your computer and use it in GitHub Desktop.
RAC Extension for ReactiveCocoa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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