A.J. S.
A.J. S.

Reputation: 218

How To Load Multiple PFFiles from Parse in Xcode

I am using Parse for an iOS app and it requires me to load multiple image in one PFObject, and so I have multiple PFFiles in that object. I know you have to load each object seperately in order to use it, but is there a way to load multiple PFFiles at once from an object? Any input is appreciated!

Upvotes: 3

Views: 1443

Answers (2)

tmr
tmr

Reputation: 1530

for other new folks like me, i believe the accepted answer from 'ahar083' may have a typo in it. i changed 'data1' to 'file1' and 'data2' to 'file2' (updated code = pasted below). i do not have enough points to comment on an answer = posted my comment as a new answer.

PFQuery *query = [PFQuery queryWithClassName:@"ManyFileClass"];
[query getObjectInBackgroundWithId:@"OBJECT_ID" 
                             block:^(PFObject *manyFileClass, NSError *error) {
    PFFile* file1 = [o objectForKey:@"file1"];
    PFFile* file2 = [o objectForKey:@"file2"];

    [file1 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {
            NSLog(@"Got data from file1@");
        }
    }];

    [file2 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {
            NSLog(@"Got data from file2@");
        }
    }];

}];

Upvotes: 2

ardrian
ardrian

Reputation: 1249

When you retrieve a PFObject, you don't actually pull down any PFFiles pointed to within that object anyway, you always need to manually pull down the file, whether it is 1 file or 5 files.

PFQuery *query = [PFQuery queryWithClassName:@"ManyFileClass"];
[query getObjectInBackgroundWithId:@"OBJECT_ID" 
                             block:^(PFObject *manyFileClass, NSError *error) {
    PFFile* file1 = [o objectForKey:@"file1"];
    PFFile* file2 = [o objectForKey:@"file2"];

    [data1 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {
            NSLog(@"Got data from file1@");
        }
    }];

    [data2 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {
            NSLog(@"Got data from file2@");
        }
    }];

}];

Upvotes: 0

Related Questions