Brilliant Example!
Hey first off - thanks so much for your example- I'm very new to obj C and IPhone dev and found this utility to be very useful. Caching is such a common task.
Some brief questions and suggestions:
1> Where does the file go? What about cleanup, I'd hate to cache a few hundred images and then leave them in limbo?
I did a NSLOG and see the file goes here...
/var/folders/RJ/RJWwAcBZFtC36gaSUm0wKU+++TI/-Tmp-/ad.jpg
I tried to use finder to actually find the file to delete it, so I can test it again.
Suggestions or maybe post some additional help to extend the utilities class with two additional method (clearImage) to have a clear a single image (by filename) or the entire image cache (clearImageCache) ?
BTW - I updated your original code to take a filename arg. It seemed like you'd want a handle on that - for doing things like the forementioned cleanup..
Finally - here's an example of how to create and call your class:
// Assumes you've included the class in the header.
// ImageName is the url of an image (NSSTRING)
//imgView is the image (UIImageView)
Utilities *utils = [[Utilities alloc] init];
UIImage *tempImg = [utils getCachedImage:ImageName];
[imgView setImage:tempImg];
// ...
[Utilities release];
Again fab example!
Last edited by dvpweb; 05-13-2009 at 10:14 AM.
|