title: NSCache Not Working Properly , Not Able To Load Images From Cache
body: <p>Since NSCache Has Been changed to generic type NSCache Now then this is the piece of code I am executing 
  however , the console is printing -" After Image To Cache" &amp; Dispatch Main Queue CustomImageView but Image From Cache Executed is not showing up in there !! maybe its not getting stored in cache that I am creating ! Any helps ? would be appreciated </p>
  
  <pre><code>let imageCache = NSCache&lt;AnyObject, AnyObject&gt;()
  </code></pre>
  
  <p>class CustomImageView: UIImageView
  {
      var imageURLString : String?</p>
  
  <pre><code>func loadImageUsingURlString(urlString: String)
  {
      imageURLString = urlString
  
      let url = URL(string: urlString)
  
      image = nil
      if let imageFromCache = imageCache.object(forKey: urlString as AnyObject ) as? UIImage
      {
          self.image = imageFromCache
          print("Image From Cache Executed")
          return
      }
  
  
  
      URLSession.shared.dataTask(with: url!, completionHandler:
      {
          (data, response, error) in
  
          if error != nil
          {
              print(error ?? "loadImageUsingURlString | Class : Helpers -&gt; CustomImageView")
              return
          }
  
          DispatchQueue.main.async
          {
              let imageToCache = UIImage(data: data!)
              print("After Image To Cache")
  
  
              if self.imageURLString == urlString
              {
                  print("Dispatch Main Queue CustomImageView[![enter image description here][1]][1]")
                  self.image = imageToCache
  
              }
              else
              {
                          imageCache.setObject(imageToCache!, forKey: urlString as AnyObject)
              }
  
  
  
          }
  
      }).resume()
  }
  </code></pre>
  
  <p>}</p>