I’m loading an image file from a web server, and then saving it to nsuserdefaults. the save code is roughly:
NSData *imageData = UIImagePNGRepresentation(theImage); // theImage is a UIImage
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:imageData forKey:string]; // string is a 3-dig number which identifies image
Now, apparently I’m on the wrong foot already, since images are not recommended for nsuserdefaults..
But what I want to do is save these images somewhere, so they can be accessed without having to re-download them. Additionally, I would like to delete old images (let’s say a day old, or keep only the last 10 downloaded images)? Is there a good technique for this?
I would use the excellent ASIHTTPRequest library to download the image in the first place 🙂
This replaces NSURLConnection and you can specify how to cache the images – you would just re-request the images from the same URL and ASIHTTPRequest would return the cached ones.