I have a Parse classes "Activity" and "Photo". How to fetch NSArray of PFObjects liked images from currentUser?
PFQuery *queryLikedPhoto = [PFQuery queryWithClassName:@"Activity"];
[queryLikedPhoto whereKey:@"type" equalTo:@"like"];
[queryLikedPhoto whereKey:@"fromUser" equalTo:[PFUser currentUser]];
[queryLikedPhoto includeKey:@"photo"];
[queryLikedPhoto findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (PFObject *object in objects) {
PFObject *photoObject = [object objectForKey:@"photo"];
[photoObject fetchIfNeededInBackgroundWithBlock:^(PFObject *photoObjects, NSError *error) {
NSLog(@"photoObjects: %@", photoObjects);
}];
}
}
}];
And it retrieve PFOjects with images, but how to save it to NSArray for further using?! (variants with NSMutableArray doesn't work):
PhotoObjects: <Photo: 0x166baf30, objectId: Q0H7XKYeCU, localId: (null)> {
image = "<PFFile: 0x166ba810>";
thumbnail = "<PFFile: 0x166ba450>";
user = "<PFUser: 0x1668c6f0, objectId: qGYdDnAtbD, localId: (null)>";
username = "Tim";
}
2015-10-18 23:39:57.058 MyApp[5817:572564] photoObjects: <Photo: 0x166bdec0, objectId: eWGonc9YLz, localId: (null)> {
image = "<PFFile: 0x166bd9e0>";
thumbnail = "<PFFile: 0x166bd6a0>";
user = "<PFUser: 0x1668c6f0, objectId: qGYdDnAtbD, localId: (null)>";
username = "Steve";
}
This query looks better Edit:
PFQuery *queryLikedPhoto = [PFQuery queryWithClassName:@"Activity"];
[queryLikedPhoto whereKey:@"type" equalTo:@"like"];
[queryLikedPhoto whereKey:@"fromUser" equalTo:[PFUser currentUser]];
[queryLikedPhoto whereKeyExists:@"photo"];
[queryLikedPhoto findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
self.likedPhotoObjects = [NSMutableArray array];
if (objects.count >0) {
for (PFObject *object in objects) {
PFObject *photoObject = [object objectForKey:@"photo"];
[self.likedPhotoObjects addObject:photoObject];
}
}
[self.collectionView reloadData];
}
}];