ACKReactiveExtensions
ACKReactiveExtensions copied to clipboard
Make `reactive.imageURL` optional
Use case
When adding images to UIImageView using AlamofireImage, the binding target extension should be of type BindingTarget<URL?> for simple reason. If new imageURL is set AlamofireImage automatically cancels running request for previous URL (if any). But if new model has no imageURL, then imageView.af_cancelImageRequest() should be called to cancel current image request (if any).
Possible solution
There are two possible solutions:
- Add
imageView.reactive.cancelImageRequest: BindingTarget<Void>and call it ifnilis assigned - make
imageView.reactive.imageURLof typeBindingTarget<URL?>and ifnilthenimageView.af_cancelImageRequest()will be called
I'd prefer the 2nd solution as it fits our needs best.
https://github.com/AckeeCZ/ACKReactiveExtensions/blob/145af295341226f41202450314129a08c8d80f2a/ACKReactiveExtensions/AlamofireImage/AlamofireImageExtensions.swift#L14