AckeeCZ / ACKReactiveExtensions

Set of useful extensions for ReactiveSwift & ReactiveCocoa
MIT License
17 stars 4 forks source link

Make `reactive.imageURL` optional #34

Closed olejnjak closed 6 months ago

olejnjak commented 5 years ago

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:

  1. Add imageView.reactive.cancelImageRequest: BindingTarget<Void> and call it if nil is assigned
  2. 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.

https://github.com/AckeeCZ/ACKReactiveExtensions/blob/145af295341226f41202450314129a08c8d80f2a/ACKReactiveExtensions/AlamofireImage/AlamofireImageExtensions.swift#L14

olejnjak commented 6 months ago

AlamofireImage extensions will be deprecated.