当有子节点时,Firebase iOS上的.children属性显示为零

几天前我提出了关于从Firebase检索数据的问题 。 问题的答案包括通过使用FEventTypeValue和快照上的.children属性的子节点的for-loop。 它完美的工作,做我需要做的事情。

但是,我试过使用类似的逻辑,它显示.children为零。

这里是数据的样子:

--languagesList ----English -------Ari ---------Age: 28 ---------Country: United States ---------distance: 2 -------Philip ---------Age: 27 ---------Country: United States ---------distance: 1 ----Spanish -------Mauricio ---------Age: 30 ---------Country: Mexico ---------distance: 4

这是代码示例(它在viewDidLoad中):

 NSString* selectedLanguagePath = [NSString stringWithFormat:@"languagesList/%@", [DataSource sharedInstance].languageSelected]; Firebase *languagesRef = [[DataSource sharedInstance].ref childByAppendingPath:selectedLanguagePath]; [[languagesRef queryOrderedByChild:@"distance"] observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) { for ( FDataSnapshot *child in snapshot.children) { NSDictionary *dict = child.value; NSString *uid = child.key; NSLog(@"%@", child.key); NSLog(@"%@", child.value); NSLog(@"%@", snapshot.key); NSLog(@"%@", snapshot.value); [self.distanceMutableArray addObject:dict]; } NSLog(@"%@", snapshot.key); NSLog(@"%@", snapshot.value); NSLog(@"%@", snapshot.children); NSLog(@"%lu", (unsigned long)snapshot.childrenCount); NSLog(@"%@", snapshot.priority); NSLog(@"%@", snapshot.ref); NSLog(@"%@", self.distanceMutableArray); }]; 

在这个例子中,for循环永远不会运行,因为.children是零。 snapshot.key是“英文”,在这种情况下是正确的。 Snapshot.childrenCount是零,但它不应该是。

有什么build议? 我想要做的是用距离sorting代码的“英语”节点中的所有信息填充数组。 所以这将是一个字典数组,看起来像这样:

 NSArray* englishArray = @[@{"Age": @27, "Country": @"United States", "distance": @1}, @{"Age": @28, "Country": @"United States", "distance": @2} 

};

还有一点,在我的安全和规则中,我有:

 "languagesList": {".read": true, ".write": true, ".indexOn" : "distance"} 

所以这是一个愚蠢的错误,但我认为可以帮助未来的人:

我的节点标题为“英文”,[数据源sharedInstance] .languageSelected为“英文”

基本上,Firebase中的节点区分大小写。