我正在尝试访问方法块,但我不知道如何:
__block NSString *username;
PFUser *user = [[self.messageData objectAtIndex:indexPath.row] objectForKey:@"author"];
[user fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) {
username = [object objectForKey:@"username"];
NSLog(@"%@", username); //returns "bob";
}];
NSLog(@"%@", username); //returns null
如何从块外的代码中访问变量“用户名”?