Reputation: 4570
How to get last added record from "history", in history we are adding key as string like "02112017" (date: ddMMyyyy).
Way we are adding history key as string of day(02112017)?, because of if we will need to show history based on a specific day for example 31/Oct/2017 then just we find key like "31102017".
Now our problem is how to get last added record.
We can not get using queryLimited(toLast: 1) of queryLimited(toFirst: 1), it will get wrong result.
let ref = "<--history path-->"
ref.queryLimited(toLast: 1).observeSingleEvent(of: .childAdded, with: { (snapshot) in
print(snapshot);
});
Upvotes: 0
Views: 984
Reputation: 772
You can store your date in the form YYYYMMDD, it is then sortable in date order. For example, represent November 2 2017 as 20171102.
When you set up your query, order it by key and then limit it to the last value.
Upvotes: 3