RxKingfisher is a Reactive Extension for Kingfisher - a lightweight, pure-Swift library for downloading and caching images from the web.
It provides Reactive Extensions on top of Kingfisher's .kf
namespace, via .kf.rx
and introduces two main usages:
Every Image view supports two different options for binding a URL to an Image view.
optionSelected // Observable<URL>
.bind(to: image.kf.rx.image(options: [.transition(.fade(0.2))])
.disposed(by: disposeBag)
OR
optionSelected
.flatMap { url in imageView.kf.rx.setImage(with: url, options: [.transition(.fade(0.2))]) }
.subscribe(onNext: { image in
print("Image successfully loaded and set on Image view: \(image)")
})
.disposed(by: disposeBag)
Every KingfisherManager
supports fetching an image from a URL, returning a Single<Image>
:
tappedButton
.flatMapLatest { KingfisherManager.shared.rx.retrieveImage(with: urlToImage) }
.subscribe(onNext: { image in
print("Image successfully loaded: \(image)")
})
.disposed(by: disposeBag)
RxKingfisher is released under the MIT license. See LICENSE for details.