I am currently retrieving my UITableViewCell thumbnail images from CoreData. It is a 2k maximum png.
It is working fine actually, and user didn’t notice any slowness, but I would like to improve the mechanism avoiding too many CoreData request.
Infact the cell is loaded when needed, and this is fine, however the point is that a request to CoreData is always made for each cells that pass to display. A possible solution is to load thumbnail only when table view stop scrolling, but with this solution, the cell is displayed with a common shared image, because I have implemented prepareForReuse which actually reset the cell.
So, is there a simple way for caching CoreData images, I suppose in memory, and retrieve it ?
My Objective-c knowledge is still limited, so the quickest solution I can think of is an NSIndexPath.row->UIImage dictionary (my table has no sections), but I don’t know if other simple and elegant solution can be implemented.
The solution seems very simple and elegant to me. I can only point your attention to use NSCache instead of dictionary, fo various reasons. Auto removal is one of them, you can also set different removal policies, limit and many more (acces from different thread with no locking doesn’t seem to fit your case). So this may save you just those few lines of code.