6

我正在使用解析来存储我的对象。当我去检索对象时,我以看起来像的随机顺序获取对象。我相信 Parse 不考虑秒数,只考虑几分钟,如果对象是在同一分钟内制作的,它会以随机顺序返回对象。

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

我正在用钥匙“过滤”我得到的对象。

我得到了这些对象,但它们都乱了套。我可以在创建此对象时将毫秒附加到它(dateSince1970 类型的东西),但我不想这样做。Parse 中有内置的方法吗?

4

3 回答 3

37

是的,Parse 提供了内置功能。
您可以使用类的 updatedAt 或 createdAt 属性。你也把它放在查询中。

// 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"];
于 2013-07-23T05:58:22.410 回答
5

我希望它会帮助你

 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.
    }
 }];
于 2013-07-23T05:49:40.507 回答
2

Parse 本身会保存它的创建和更新日期。也许您想使用它的创建日期。

查看此文档:https ://parse.com/docs/ios_guide#top/iOS

例子:

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

希望这可以帮助你...

编辑:

// 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"];
于 2013-07-23T05:49:50.747 回答