Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get most recently added parse.com object

Is there any way to do a query in Parse to get the most recently added PFObject type?

I know that I can do a query with a greater than criteria, but it would be very useful if there was a function to get the most recent object added when no date is known.

like image 848
Atma Avatar asked Jul 04 '13 02:07

Atma


1 Answers

Just add a descending order on createdAt and get the first object:

PFQuery *query = [PFQuery queryWithClassName:@"YourClassName"];
[query orderByDescending:@"createdAt"];
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
    // code
}];

In Swift:

var query = PFQuery(className: "YourClassName")
query.orderByDescending("createdAt")
query.getFirstObjectInBackgroundWithBlock {(object: PFObject?, error: NSError?) -> Void in
    // code
}
like image 85
Eric Qian Avatar answered Nov 15 '22 18:11

Eric Qian