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