views:

330

answers:

1

Hi.I am making an app that it takes photos from web site for some Username and shows it on UITable with username then when clicking user name it shows photos for this user and then clicking to name of photo it shows full screen photo.

My question is I am using NSData to get photos from internet.Am I have to save also those data to CoreDAta? I am using like when pressing name of user it again creates NSData and downloads photos from internet and shows them on UITable. And it takes time.

What is good approach? and How can save this images to CoreDAta?

I am using this method

NSData *imageData=[flickr dataForPhotoID:firstPhoto.id fromFarm:firstPhoto.farm 
onServer:firstPhoto.server withSecret:firstPhoto.secret inFormat: 
FlickrFetcherPhotoFormatSquare];

and here definition of dataForPtohoID method

- (NSData *)dataForPhotoID:(NSString *)photoID fromFarm:(NSString *)farm   
   onServer:(NSString *)server withSecret:(NSString *)secret 
 inFormat:(FlickrFetcherPhotoFormat)format {

#if TEST_HIGH_NETWORK_LATENCY
sleep(1);
#endif

NSString *formatString;

switch (format) {
    case FlickrFetcherPhotoFormatSquare:    formatString = @"s"; break;
    case FlickrFetcherPhotoFormatLarge:     formatString = @"b"; break;
}

NSString *photoURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_%@.jpg", farm, server, photoID, secret, formatString];
NSURL *url = [NSURL URLWithString:photoURLString];

return [NSData dataWithContentsOfURL:url];
}
+4  A: 

First, always store your images in a usable format such as PNG or JPEG instead of NSData. This will save you a lot of headaches.

Second, the rule for storing binary data is:

  • < 100kb store in the same table as the relevant data
  • < 1mb store in a separate table attached via a relationship to avoid loading unnecessarily
  • > 1mb store on disk and reference it inside of Core Data

Update

The storage inside of Core Data should be binary and you can write accessor methods for it. Take a look at this answer: http://stackoverflow.com/questions/2271195/core-data-images-from-desktop-to-iphone/2274916#2274916

Update

The example code I linked to describes how to create accessors in your NSManagedObject subclass that will convert the image back and forth between a UIImage and binary data.

Marcus S. Zarra
Thanks for advise but in table which data type i must use? Binary? Or Nsstring?And converting to jpeg is there any method?
Meko
In your thread I couldent understand that I must use this functions with creating new class ?or simply in my UIView ?
Meko