我有一個解析類「活動」和「照片」。如何從當前用戶獲取PFObjects喜歡的圖像的NSArray? 如何從當前用戶獲取所有喜歡的圖片(指針)?
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);
}];
}
}
}];
它檢索與圖像PFOjects,但如何將其保存到NSArray中進一步使用? (與NSMutableArray的變種不工作):
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"; }
這個查詢看起來更好 編輯:
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];
}
}];
@ lightice11閱讀時,我一直在努力,檢索和寫入的NSMutableArray但總是空,沒有任何解決方案如何保存以供進一步使用?! – vbondarenko3d