How can I get the objects in the order in which they were created?

I use parsing to store my objects. When I go to search for objects, I get the objects in random order, as it looks. I Believe Parse does not count seconds, just a few minutes, and if the objects are made in one minute, this returns me the objects in random order.

PFQuery *query = [PFQuery queryWithClassName:@"ChatMessage"]; [query whereKey:@"alert" equalTo:myAlert]; 

I "filter" the objects that I get with the key.

I get objects, but they are all out of order. I can attach milliseconds to this object when it is created (date typeSince1970), but I do not want to do this. Is there a built-in way to do this in Parse?

+6
source share
3 answers

Yes, there is a built-in feature provided by Parse.
you can use updatedAt or createdAt class attributes. and you also add this to the request.

 // Sorts the results in ascending order by the created date [query orderByAscending:@"createdAt"]; // Sorts the results in descending order by the created date [query orderByDescending:@"createdAt"]; 
+36
source

I hope this helps you

  PFQuery *query = [PFQuery queryWithClassName:@"ChatMessage" ]; [query orderByDescending:@"createdAt"]; query.limit =10; [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { //you will get all your objectsas per u created ur object in parse. } }]; 
+5
source

The syntax itself saves the date when it was created and updated. You might want to use the date it was created.

Take a look at this documentation: https://parse.com/docs/ios_guide#top/iOS

Example:

 NSDate *updatedAt = gameScore.updatedAt; NSDate *createdAt = gameScore.createdAt; 

Hope this helps you ...

Edit:

 // Sorts the results in ascending order by the score field [query orderByAscending:@"score"]; // Sorts the results in descending order by the score field [query orderByDescending:@"score"]; 
+2
source

Source: https://habr.com/ru/post/950044/


All Articles