Skip to content

Instantly share code, notes, and snippets.

@Pablo-Merino
Created May 15, 2011 11:07
Show Gist options
  • Save Pablo-Merino/973051 to your computer and use it in GitHub Desktop.
Save Pablo-Merino/973051 to your computer and use it in GitHub Desktop.
NSString *imageName =[NSString stringWithString:[(Tweet*)[tweets objectAtIndex:indexPath.row] author]];
NSString *userImage =[NSString stringWithString:[(Tweet*)[tweets objectAtIndex:indexPath.row] profileImage]];
NSArray *myArray = [userImage componentsSeparatedByString: @"/"];
NSString *fileName = (NSString*)[myArray lastObject];
NSString *picName =[NSString stringWithFormat:@"%@:%@", imageName, fileName];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/ProfilePictures"];
NSString* path = [dataPath stringByAppendingPathComponent:picName];
UIImage* image = [UIImage imageWithContentsOfFile:path];
if (!image) {
UIImage *phoneImage=[UIImage imageWithData:[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:userImage]]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/ProfilePictures"];
NSString* path = [dataPath stringByAppendingPathComponent:picName];
NSData* data = UIImagePNGRepresentation(phoneImage);
[data writeToFile:path atomically:YES];
}
else{
[cell.imageView setImage:image];
}
@md347
Copy link

md347 commented May 15, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment