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

The .children property on Firebase iOS shows up as nil when there are child nodes

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

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

数据如下:

--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 为 nil。 snapshot.key 是 "English",在这种情况下是正确的。 Snapshot.childrenCount 虽然是零,但它不应该是。

有什么建议吗?我想要做的是用代码的 "English" 节点中的所有信息填充一个数组,该节点按距离排序。所以这将是一个看起来像这样的字典数组:

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

};

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

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

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

我的节点标题为 "english",[DataSource sharedInstance].languageSelected 为 "English"

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