Skip to content

Instantly share code, notes, and snippets.

@orff
Created August 3, 2010 16:13
Show Gist options
  • Save orff/506649 to your computer and use it in GitHub Desktop.
Save orff/506649 to your computer and use it in GitHub Desktop.
- (void)storeKeyToDisk:(NSString *)key
{
UIImage *image = [[self imageFromKey:key fromDisk:YES] retain]; // be thread safe with no lock
if (image != nil)
{
NSString *searchForMe = @"png";
NSRange range = [key rangeOfString : searchForMe];
if (range.location != NSNotFound) {
[[NSFileManager defaultManager] createFileAtPath:[self cachePathForKey:key] contents:UIImagePNGRepresentation(image) attributes:nil];
} else {
[[NSFileManager defaultManager] createFileAtPath:[self cachePathForKey:key] contents:UIImageJPEGRepresentation(image, (CGFloat)1.0) attributes:nil];
}
[image release];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment