我正在使用Firebase 2.5.1开发macOS Swift项目。它基本上是一个CRUD系统。
我将从childWithAutoID创建数据路径的方式更改为自定义字符串,主要是因为我想避免重复输入。
我将所有数据上传到Firebase并成功使用此新路径(约5000个条目)。我可以使用以下代码检索它:
//Constants.booksFirebase equals my parent path of Firebase
Constants.booksFirebase.queryOrderedByChild("rentedCount").queryLimitedToLast(10).observeEventType(.Value, withBlock: { snap in
let results = snap.value as? NSDictionary
if let results = results {
self.books = []
for obj in results {
let id = obj.key as! String
self.books.append(id)
}
}
})
但是,如果我查询所有值,我会得到一个推文:"无法使用具有相同排序的键创建FImmutableSortedDictionary!"。我查询的方式它与上面没有限制的示例完全相同:Constants.booksFirebase.queryOrderedByChild("rentedCount").observeEventType(.Value, withBlock:{...}
奇怪的是,我有来自其他路径的另一组数据Constants.peopleFirebase
,它使用上述相同的逻辑,但不会引发异常。
我认为Firebase可能会使用相同的密钥上传两个对象,但这只是一个假设。
你知道这个错误意味着什么吗?
我已经看过这个,但它并没有帮助我: Firebase: Can't create FImmutableSortedDictionary with keys with same ordering
谢谢, 马塞洛
完成以下错误:
2016-08-29 21:42:00.846 ProSaber[16218:19613620] An uncaught exception was raised
2016-08-29 21:42:00.846 ProSaber[16218:19613620] Can't create FImmutableSortedDictionary with keys with same ordering!
2016-08-29 21:42:00.846 ProSaber[16218:19613620] (
0 CoreFoundation 0x00007fff94d934f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff93ec4f7e objc_exception_throw + 48
2 CoreFoundation 0x00007fff94dfa4bd +[NSException raise:format:] + 205
3 Firebase 0x00000001001e518f __55+[FTreeSortedDictionary fromDictionary:withComparator:]_block_invoke99 + 143
4 CoreFoundation 0x00007fff94d0dc36 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 134
5 CoreFoundation 0x00007fff94d0dac9 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 217
6 Firebase 0x00000001001e4fbc +[FTreeSortedDictionary fromDictionary:withComparator:] + 315
7 Firebase 0x00000001001dd774 +[FImmutableSortedDictionary fromDictionary:withComparator:] + 105
8 Firebase 0x00000001001f67b1 +[FSnapshotUtilities internalNodeFrom:priority:withValidationFrom:atDepth:path:] + 1665
9 Firebase 0x00000001001f60ea +[FSnapshotUtilities nodeFrom:priority:withValidationFrom:atDepth:path:] + 120
10 Firebase 0x00000001001f602e +[FSnapshotUtilities nodeFrom:priority:withValidationFrom:] + 147
11 Firebase 0x00000001001f5f29 +[FSnapshotUtilities nodeFrom:priority:] + 55
12 Firebase 0x00000001002186d1 -[FRepo onDataUpdate:forPath:message:isMerge:tagId:] + 672
13 Firebase 0x000000010022212a -[FPersistentConnection onDataPushWithAction:andBody:] + 591
14 Firebase 0x000000010021eed3 -[FPersistentConnection onDataMessage:withMessage:] + 709
15 Firebase 0x000000010023bd75 -[FConnection onDataMessage:] + 116
16 Firebase 0x000000010023bcac -[FConnection onMessage:withMessage:] + 282
17 Firebase 0x000000010023add0 -[FWebSocketConnection appendFrame:] + 360
18 Firebase 0x000000010023ae8b -[FWebSocketConnection handleIncomingFrame:] + 132
19 Firebase 0x000000010023679f __31-[FSRWebSocket _handleMessage:]_block_invoke + 129
20 libdispatch.dylib 0x0000000100993070 _dispatch_call_block_and_release + 12
21 libdispatch.dylib 0x0000000100985cc5 _dispatch_client_callout + 8
22 libdispatch.dylib 0x000000010098b112 _dispatch_queue_drain + 351
23 libdispatch.dylib 0x0000000100992e24 _dispatch_queue_invoke + 557
24 libdispatch.dylib 0x0000000100989dab _dispatch_root_queue_drain + 1226
25 libdispatch.dylib 0x00000001009898a5 _dispatch_worker_thread3 + 106
26 libsystem_pthread.dylib 0x00000001009e8336 _pthread_wqthread + 1129
27 libsystem_pthread.dylib 0x00000001009e5f91 start_wqthread + 13
)
2016-08-29 21:42:00.847 ProSaber[16218:19613620] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't create FImmutableSortedDictionary with keys with same ordering!'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff94d934f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff93ec4f7e objc_exception_throw + 48
2 CoreFoundation 0x00007fff94dfa4bd +[NSException raise:format:] + 205
3 Firebase 0x00000001001e518f __55+[FTreeSortedDictionary fromDictionary:withComparator:]_block_invoke99 + 143
4 CoreFoundation 0x00007fff94d0dc36 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 134
5 CoreFoundation 0x00007fff94d0dac9 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 217
6 Firebase 0x00000001001e4fbc +[FTreeSortedDictionary fromDictionary:withComparator:] + 315
7 Firebase 0x00000001001dd774 +[FImmutableSortedDictionary fromDictionary:withComparator:] + 105
8 Firebase 0x00000001001f67b1 +[FSnapshotUtilities internalNodeFrom:priority:withValidationFrom:atDepth:path:] + 1665
9 Firebase 0x00000001001f60ea +[FSnapshotUtilities nodeFrom:priority:withValidationFrom:atDepth:path:] + 120
10 Firebase 0x00000001001f602e +[FSnapshotUtilities nodeFrom:priority:withValidationFrom:] + 147
11 Firebase 0x00000001001f5f29 +[FSnapshotUtilities nodeFrom:priority:] + 55
12 Firebase 0x00000001002186d1 -[FRepo onDataUpdate:forPath:message:isMerge:tagId:] + 672
13 Firebase 0x000000010022212a -[FPersistentConnection onDataPushWithAction:andBody:] + 591
14 Firebase 0x000000010021eed3 -[FPersistentConnection onDataMessage:withMessage:] + 709
15 Firebase 0x000000010023bd75 -[FConnection onDataMessage:] + 116
16 Firebase 0x000000010023bcac -[FConnection onMessage:withMessage:] + 282
17 Firebase 0x000000010023add0 -[FWebSocketConnection appendFrame:] + 360
18 Firebase 0x000000010023ae8b -[FWebSocketConnection handleIncomingFrame:] + 132
19 Firebase 0x000000010023679f __31-[FSRWebSocket _handleMessage:]_block_invoke + 129
20 libdispatch.dylib 0x0000000100993070 _dispatch_call_block_and_release + 12
21 libdispatch.dylib 0x0000000100985cc5 _dispatch_client_callout + 8
22 libdispatch.dylib 0x000000010098b112 _dispatch_queue_drain + 351
23 libdispatch.dylib 0x0000000100992e24 _dispatch_queue_invoke + 557
24 libdispatch.dylib 0x0000000100989dab _dispatch_root_queue_drain + 1226
25 libdispatch.dylib 0x00000001009898a5 _dispatch_worker_thread3 + 106
26 libsystem_pthread.dylib 0x00000001009e8336 _pthread_wqthread + 1129
27 libsystem_pthread.dylib 0x00000001009e5f91 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
答案 0 :(得分:0)
我不确定错误。这听起来很奇怪,但queryOrderedByChild旨在与queryStartingAtValue,queryEndingAtValue或queryEqualToValue一起使用。您仍然可以在之后进一步限制查询,但我相信查询是期望参数,因为您提供的不是,所以它不知道在哪里查询最多10条记录。例如,如果您有100条记录并且您的查询仅限于10条,那么查询无法知道在没有这些参数的情况下您真正尝试查看的10条记录。
答案 1 :(得分:0)
我最终使用了childByAutoId()来避免Firebase数据中可能出现重复的密钥。有关详细信息,请参阅有关matthew答案的讨论。