Download and cache images in UITableViewCell

Swift 3: Flickering can be avoided by this way: Use the following code in public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell cell.photoImageView.image = nil //or keep any placeholder here cell.tag = indexPath.row let task = URLSession.shared.dataTask(with: imageURL!) { data, response, error in guard let data = data, error == nil else { … Read more

How to use NSCache

You use it the same way you would use NSMutableDictionary. The difference is that when NSCache detects excessive memory pressure (i.e. it’s caching too many values) it will release some of those values to make room. If you can recreate those values at runtime (by downloading from the Internet, by doing calculations, whatever) then NSCache … Read more