以下代码显示了一个奇怪的输出:
- (void)viewDidLoad {
[super viewDidLoad];
self.name = [[NSMutableArray alloc]init];
self.email = [[NSMutableArray alloc]init];
self.url = [[NSMutableArray alloc]init];
self.dataFromServer = [[NSDictionary alloc] init];
self.ref = [[FIRDatabase database] reference];
[[[_ref child:@"FriendsList"] child:[FIRAuth auth].currentUser.uid] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
NSLog(@"check flist%@", snapshot.value);
self.dataFromServer = snapshot.value;
self.uids = [_dataFromServer allValues];
NSLog(@"%li",[self.uids count]);
int i = 0;
while (i != [self.uids count]) {
NSString *go = [self.uids objectAtIndex:i];
[[[_ref child:@"UserPools"]child:go] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
self.dataFromServer = snapshot.value;
[self.name addObject:[_dataFromServer valueForKey:@"username"]];
[self.email addObject:[_dataFromServer valueForKey:@"email"]];
[self.url addObject:[_dataFromServer valueForKey:@"photoURL"]];
NSLog(@"loop %@%@%@%@",self.name,self.email,self.url,self.uids);
return;
}];
i = i + 1;
}
NSLog(@"Down loop%@%@%@%@",self.name,self.email,self.url,self.uids);
return;
}];
NSLog(@"Out side%@%@%@%@",self.name,self.email,self.url,self.uids);
[self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([myCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([myCell class])];
}
输出结果为:
2016-10-09 19:34:56.941 obcChat[80961:1055796] Out side(
)(
)(
)(null)
2016-10-09 19:34:57.448 obcChat[80961:1055796] check flist{
xx = dKC8D8GMFiSoPFDCuSzBpEpcjnl1;
}
2016-10-09 19:34:57.449 obcChat[80961:1055796] 1
2016-10-09 19:34:57.449 obcChat[80961:1055796] Down loop(
)(
)(
)(
dKC8D8GMFiSoPFDCuSzBpEpcjnl1
)
2016-10-09 19:34:58.284 obcChat[80961:1055796] loop (
Yang
)(
"test@gmail.com"
)(
"https://firebasestorage.googleapis.com/v0/b/obcchat-525bf.appspot.com/o/images%2FdKC8D8GMFiSoPFDCuSzBpEpcjnl1? alt=media&token=b1fbb306-c6f6-4c12-b467-eb4130d533a0"
)(
dKC8D8GMFiSoPFDCuSzBpEpcjnl1
)
为什么输出始终打印最后NSLOG
然后打印其他NSLOG
?
代码正在尝试从Firebase获取数据,然后使用数据获取新数据。我是编码的新手。请解释并感谢。