我知道这个函数首先返回“图像”,然后“findObjectsInBackgroundWithBlock”检索数据,这就是为什么结果为零。Obj-C类的方法结果从块
1 - 如何从块返回数组?
2 - 如何把这个块不在主线程中?
+(NSMutableArray *)fetchAllImages{
__block NSMutableArray *images = [NSMutableArray array];
PFQuery *query = [PFQuery queryWithClassName:@"Photo"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (PFObject *object in objects) {
PFFile *applicantResume = object[@"imageFile"];
NSData *imageData = [applicantResume getData];
NSString *imageName = [ImageFetcher saveImageLocalyWithData:imageData FileName:object.objectId AndExtention:@"png"];
[images addObject:imageName];
// here images is not empty
}
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
// here images is empty
return images;
}
谢谢你:) – 2015-02-08 19:18:29