iosobjective-cparsinguiimagepffile

How to convert a batch of PFFiles to UImages?


In my app, images are being stored on parse. They then get retrieved into an array of PFFiles, however I have to convert them individually to UIImages using this method which takes time.

  PFFile *picture = [pictureArray objectAtIndex:indexPath.row];
[picture getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {

    myimage = [UIImage imageWithData:data];

}];

So I need to store images on parse, and retrieve them, and I don't want to individually convert all of these pictures, I want it all done at once. These are the options I currently see:

  1. Create a loop that loops the code above to convert all the PFFiles to UIImages and add them to an array ready to access.

  2. Find a better way to convert or use PFFiles.

  3. Upload NSData or something else to parse so I don't have to convert the PFFiles.

Can anyone provide me advice or solutions to my problem? As I am presenting a fairly large amount of images in a UICollectionView, I want them to be all loaded at once some how instead of having to load them individually, I want the images in an array ready to go so I can just call:

cell.myimage.image = [pictureArray objectAtIndex:indexPath.row];

and all the images will be loaded instead of waiting for PFFIles to be converted etc.


Solution

  • If you want to present them you should use PFImageView which can load the by itself. It's a subclass of UIImageView and its pretty.

    Example:

    PFImageView *creature = [[PFImageView alloc] init];
    creature.image = [UIImage imageNamed:@”1.jpg”]; // placeholder image
    creature.file = (PFFile *)file;
    [creature loadInBackground];
    

    If you want to download them for other uses check out this answer.