title: How to get UIImage from AnyPublisher<UIImage?, Never> Swift 5 (Combine framework)
body: <p>Im trying to figure how to use <a href="https://medium.com/flawless-app-stories/reusable-image-cache-in-swift-9b90eb338e8d" rel="nofollow noreferrer">Reusable Image Cache in Swift</a> with a UIImageView. I am trying to simply assign the ImageLoader() variable's, actual image to a UIImageView so I can use it as a UIImage.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>let loader = ImageLoader()
  
  myImage.image = loader.loadImage(from: myUrl)
  </code></pre>
  
  <p>maybe:</p>
  
  <pre><code>loader.loadImage(from: myUrl)
  
  myImage.image = loader(image)
  </code></pre>
  
  <p>But this give a cannot call value of non-function type 'ImageLoader' error</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>final class ImageLoader {
  
  private let cache = ImageCache()
  
  func loadImage(from url: URL) -&gt; AnyPublisher&lt;UIImage?, Never&gt; {
      if let image = cache[url] {
          return Just(image).eraseToAnyPublisher()
      }
      return URLSession.shared.dataTaskPublisher(for: url)
          .map { UIImage(data: $0.data) }
          .catch { error in return Just(nil) }
          .handleEvents(receiveOutput: {[unowned self] image in
              guard let image = image else { return }
              self.cache[url] = image
          })
          .subscribe(on: DispatchQueue.global(qos: .background))
          .receive(on: RunLoop.main)
          .eraseToAnyPublisher()
  }
  }
  </code></pre>