title: No response or Completion Block Skipped AlamofireImage
body: <p>So I'm having a little bit of trouble trying to get AlamofireImages ImageDownloader to work. Below is the function I'm trying to use to download and later cache an image.</p>
  
  <p>I've used normal Alamofire to request images before, however, the project has evolved to include caching an image to the disk to reduce the amount of requests to the server.</p>
  
  <pre><code>var downloader: ImageDownloader? 
  
  func downloadAndCacheImage(_ url: String, imageView: UIImageView)
  {
      self.downloader = ImageDownloader()
  
      var urlRequest = try! URLRequest(url: "GiveMeAResponse.com", method: .get)
  
      self.downloader?.download(urlRequest) { response in
  
          switch response.result{
          case .success(let image):
              print("\(image) has been downloaded")
              break
          case .failure(let error):
              print("ERROR: \(response.error)")
              break
          }
  
          if let imageData = response.data{
              debugPrint("Applying image...")
              if let image = UIImage(data: imageData){
                  ImageManager.applyImage(imageView: imageView, image: image)
              }
          }
      }
  }
  </code></pre>
  
  <p>Looking through the AlamofireImage documentation <a href="https://github.com/Alamofire/AlamofireImage" rel="nofollow noreferrer">here</a>, it looks pretty simple to send a download request and I feel as though with what I have I should be getting at least a failure message. The completion block is just getting skipped all together and I'm not entirely sure why unless it has to do with this which is also in the documentation.</p>
  
  <blockquote>
    <p>Make sure to keep a strong reference to the ImageDownloader instance, otherwise the completion closure will not be called because the downloader reference will go out of scope before the completion closure can be called.</p>
  </blockquote>
  
  <p>This might be a bit of a dumb question, but am I not doing the above resulting in the closure not being called?</p>
  
  <p>If anyone has some insight, that would be awesome.</p>
  
  <p>Edit: Included strong reference to the ImageDownloader.</p>
  
  <p>Edit#2: Assigning the download to a variable and printing the response code returns a nil. (Maybe because the request is done on a different thread?)</p>
  
  <pre><code>var downloader: ImageDownloader? 
  
  func downloadAndCacheImage(_ url: String, imageView: UIImageView)
  { 
      self.downloader = ImageDownloader()
  
      var urlRequest = try! URLRequest(url: URL(string: "https://solarianprogrammer.com/images/2013/02/28/mandelbrot_piece_Z2.png")!)
  
      let downloadReciept = self.downloader?.download([urlRequest])
      print(downloadReciept?[0].request.response) // Returns nil
  
  }
  </code></pre>
  
  <p>Edit#3:
  I finally fixed it and my code now looks like this:</p>
  
  <pre><code>let downloader = ImageDownloader.default
  func downloadAndCacheImage(_ url: String, imageView: UIImageView)
  {
      var urlRequest = try! URLRequest(url: URL(string: "https://solarianprogrammer.com/images/2013/02/28/mandelbrot_piece_Z2.png")!)
  
      self.downloader.download(urlRequest) { response in
          switch response.result{
          case .success(let image):
              print("\(image) has been downloaded")
              break
          case .failure(let error):
              print("ERROR: \(response.error)")
              break
          }
  
          if let imageData = response.data{
              debugPrint("Applying image...")
              if let image = UIImage(data: imageData){
                  ImageManager.applyImage(imageView: imageView, image: image)
              }
          }
      }
  }
  </code></pre>
  
  <p>All I really changed was: </p>
  
  <pre><code>let downloader = ImageDownloader()
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>let downloader = ImageDownloader.default
  </code></pre>
  
  <p>I really hope this helps anyone who comes across this problem!</p>