问题
I have did a lot of querys, searched in websites , And already asked this question before and i didn't found a good answer!
I have Parse backend looks like this:
In my view controller I just want to show Last createdAt for each sender i want to get all the row of last object for sender:.
so we should ignore "name1: Hello" and "name2: Really when was.." because this old rows we already got new objects.
I want one result for each sender depends on createdAt
so can I get help with query to do this? or how can we do that?
let query = PFQuery(className: "test")
query.whereKey("receivers", equalTo: PFUser.currentUser()!.username!)
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in
if error == nil {
// now what? I've done everything i could none worked fine
I hope if i'll get a help to do that, So please help me if you could.
回答1:
you can just add a limit
to the query.. see parse docs..
let query = PFQuery(className: "test")
query.whereKey("receivers", equalTo: PFUser.currentUser()!.username!)
query.orderByDescending("createdAt")
query.limit = 1
query.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in
if error == nil {
回答2:
Your data model isn't really suitable for doing this operation quickly. But, how you setup your data model is dictated by all of your requirements, not just one.
To make this easy you should add a pointer from your User
to your Message
, and every time a message is sent by a user you set that pointer (which replaces the old pointer).
Now, you can simply query User
s, using includeKey
to get the message, and display your list.
来源:https://stackoverflow.com/questions/32149883/swift-parse-query-get-last-createdat-objects