ios


Firebase iOS query not ordering as expected


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.
I understand that the underlying data structure of an NSDictionary is not an ordered data structure.
What am I doing wrong?
[self.refMyOrders observeSingleEventOfType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
NSLog(#"snapshot.value = %#", snapshot.value);
NSLog(#"all keys = %#", [snapshot.value allKeys]);
}];
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.
[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.

Related Links

Firebase get child ID swift ios
Swift. Collection of inherited objects
Swift: Extending UIStackView to create a centred list of tags
How to add shadow only at the bottom of section of UITableView?
Creating Multipage PDF File using CoreGraphics shows error on console
iOS Quartz 2D - Fill area between shapes
Is CMPedometer historical data lost on upgrade to iOS10 or a Restore?
Documenting code in Xcode 8
How to get range of specific substring even if a duplicate
iOS SDK SOAP parsing error : Data at the root level is invalid. Line 1, position 1
Undefined symbols for architecture x86_64: “_AVAudioSessionCategoryPlayback”, referenced from
Swift - Unexpected subviews crash
How to save NSMutablearray that is present in a class to a file?
GameplayKit: suggestion for implementing a GKComponent to fire bullets
Swift / popViewControllerAnimated throws nil / how to go back to previous viewController?
Access app.buttons in Xcode UITest without having any usable text for referencing.

Categories

HOME
regex
opencv
lsf
ffmpeg
dynamics-crm-365
azure-search
orbeon
robotframework
azure-web-sites
libreoffice
cql3
mocha
addeventlistener
splunk
microsoft-dynamics
telnet
session-cookies
union
graph-tool
google-cloud-sdk
asp.net-mvc-5.2
group-by
partitioning
next
drupal-commerce
hp-alm
pydev
pwm
montecarlo
eonasdan-datetimepicker
apache-httpcomponents
grouping
mathdotnet
typemock-isolator
android-button
editorconfig
f2py
valueinjecter
akka-http
groove
tensor
lifecycle
aem-6
nav
jackrabbit
packaging
caldroid
btle
nexus-5
free-diameter
mobile-browser
uifont
hipi
glumpy
mysql-error-1050
vs-2015-preview
cabal-install
android-alertdialog
directsound
vb4android
activity-diagram
insert-update
geneos
mars
viewengine
asp.net-webpages
pddl
dual-table
session-replication
json4s
crosswalk
viennacl
translucency
vbo
alt
mkpolyline
imake
epoll
eventmachine
spread-toolkit
deepzoom
validform
delphi-2009
dfsort
freemind
vlfeat
git-gui
nsmanagedobjectmodel
kmz
google-goggles
osmf
java-ee-5
domain-mapping
tipsy
ccr
hpple
process.start
springboard
emacs-ecb
winamp
xoom
coords
cracker
stsadm
virtual-server

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App