title: Weird caching issue in UITableView (Swift 4)
body: <p>I'm having a very odd issue with my app, and all I can think of is that it is some sort of caching issue. Basically, when I scroll my <code>UITableView</code>, the thumbnails that are shown are being reloaded multiple times for the same row, typically with different images each time, before finally landing on the right image. </p>
  
  <p>A short (20 second) screen capture is here: <a href="https://youtu.be/oa04mlOgMeQ" rel="nofollow noreferrer">https://youtu.be/oa04mlOgMeQ</a></p>
  
  <p>The app should be caching these once loaded, and the images are named to match the bonus codes (and the name is in the JSON file). I can't figure out why it is doing this.</p>
  
  <p>EDIT: Here is my cellForRowAt code:</p>
  
  <pre><code>override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cellIdentifier = "BonusListViewCell"
          guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? BonusListViewCell else {
              fatalError("The dequeued cell is not an instance of BonusListViewCell.")
          }
          // let bonus = bonuses[indexPath.row]
          let bonus: JsonFile.JsonBonuses
          if isFiltering() {
              bonus = filteredBonuses[indexPath.row]
          } else {
              bonus = bonuses[indexPath.row]
          }
  
          let urlString = "http://tourofhonor.com/appimages/"+(bonus.imageName)
          let url = URL(string: urlString)
          cell.primaryImage.downloadedFrom(url: url!)
          cell.nameLabel.text = bonus.name.capitalized
          cell.bonusCodeLabel.text = bonus.bonusCode.localizedUppercase
          cell.categoryLabel.text = bonus.category
          cell.valueLabel.text = "\(bonus.value)"
          cell.cityLabel.text = "\(bonus.city.capitalized),"
          cell.stateLabel.text = bonus.state.localizedUppercase
  
          return cell
      }
  </code></pre>
  
  <p>Here is my <code>downloadedFrom</code> function:</p>
  
  <pre><code>extension UIImageView {
      func downloadedFrom(url: URL, contentMode mode: UIViewContentMode = .scaleAspectFit) {
          contentMode = mode
          URLSession.shared.dataTask(with: url) { data, response, error in
              guard
                  let httpURLResponse = response as? HTTPURLResponse, httpURLResponse.statusCode == 200,
                  let mimeType = response?.mimeType, mimeType.hasPrefix("image"),
                  let data = data, error == nil,
                  let image = UIImage(data: data)
                  else { return }
              DispatchQueue.main.async() {
                  self.image = image
              }
              }.resume()
      }
      func downloadedFrom(link: String, contentMode mode: UIViewContentMode = .scaleAspectFit) {
          guard let url = URL(string: link) else { return }
          downloadedFrom(url: url, contentMode: mode)
      }
  }
  </code></pre>
  
  <p>My UITableViewCell code is:</p>
  
  <pre><code>import UIKit
  
  class BonusListViewCell: UITableViewCell {
  
      //MARK: Properties
      @IBOutlet weak var bonusCodeLabel: UILabel!
      @IBOutlet weak var categoryLabel: UILabel!
      @IBOutlet weak var nameLabel: UILabel!
      @IBOutlet weak var valueLabel: UILabel!
      @IBOutlet weak var cityLabel: UILabel!
      @IBOutlet weak var stateLabel: UILabel!
      @IBOutlet weak var flavorText: UITextView!
      @IBOutlet weak var primaryImage: UIImageView!
  
      override func awakeFromNib() {
          super.awakeFromNib()
          // Initialization code
      }
  
      override func setSelected(_ selected: Bool, animated: Bool) {
          super.setSelected(selected, animated: animated)
  
          // Configure the view for the selected state
      }
  
  }
  </code></pre>