热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

FirebaseiOS查询未按预期排序-FirebaseiOSquerynotorderingasexpected

IhavesavedmydatausingchildByAutoIdsothatitisorderedchronologicallyinFirebase.WhenIq

I have saved my data using childByAutoId so that it is ordered chronologically in Firebase. When I query using the query below, and then I print the snapshot.value it prints in the orders as I expected --ordered chronologically--, but when I try to enumerate over snapshot.value, and when I try to get the keys with [snap.value allkeys], they are no longer ordered chronologically. I have tried using [self.refMyOrder queryOrderedByKey] and [self.refMyOrders queryOrderedByChild:@"timestamp" for which I have a child timestamp that is a data-type long of the Epoch time. But still, it is not maintaining the desired order.

我使用childByAutoId保存了我的数据,因此它在Firebase中按时间顺序排序。当我使用下面的查询查询,然后我打印snapshot.value它按照我预期的顺序打印 - 按时间顺序排序 - 但是当我尝试枚举snapshot.value时,以及当我尝试获取密钥时使用[snap.value allkeys],它们不再按时间顺序排序。我已经尝试使用[self.refMyOrder queryOrderedByKey]和[self.refMyOrders queryOrderedByChild:@“timestamp”,我的子时间戳是Epoch时间的数据类型。但是,它仍然没有维持所需的顺序。

I understand that the underlying data structure of an NSDictionary is not an ordered data structure.

据我所知,NSDictionary的底层数据结构不是有序的数据结构。

What am I doing wrong?

我究竟做错了什么?

[self.refMyOrders observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
    NSLog(@"snapshot.value = %@", snapshot.value);
    NSLog(@"all keys = %@", [snapshot.value allKeys]);
}];

1 个解决方案

#1


7  

So, I read the FDataSnapshot.h header file that comes with the Firebase iOS SDK, and found a way to enumerate over the snapshot so that it remains in the proper order.

因此,我阅读了Firebase iOS SDK附带的FDataSnapshot.h头文件,并找到了一种枚举快照的方法,使其保持正确的顺序。

[self.refMyOrders observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
    for (FDataSnapshot* child in snapshot.children) {
        NSLog(@"%@ -> %@", child.value[@"orderID"], child.value[@"timestamp"]);
    }
}];

This is exactly what I was looking for. I will leave this question here for future users. I couldn't find anything this simple.

这正是我想要的。我将在此留下这个问题给未来的用户。我找不到这么简单的事。


推荐阅读
author-avatar
清-新花曼的日子
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有