如何获得比一周新的解析对象

用户名

我需要从解析中获取不早于一周的对象。我正在尝试

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEEE, MMMM d yyyy"];
NSDate *date = [object createdAt];
[dateFormatter stringFromDate:date]

您的代码还有很长的路要走,并且显示出一些基本的误解。我认为您真正需要进入Parse之前去学习Objective-C和Cocoa / UIKit。然而:

解析有一个createdAt在所有对象上调用的自动列您应该使用它。

我不确定您对“一周前”的定义,但是要确切地获取一个星期前的日期以进行第二次使用:

NSDate* date = [NSDate dateWithTimeIntervalSinceNow:-60*60*24*7];

如果您的意思是“一周前的午夜”或类似的内容,则可以使用更复杂的方法,但是为了清楚起见,我将其保留不变。

使用内置的createdAt列将此日期传递给PFQuery:

PFQuery* q = [PFQuery queryWithClassName:[MyClass parseClassName]];
[q whereKey:@"createdAt" greaterThan:date];

然后发出查找:

[q findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    // here objects will contain your PFObject subclasses from the server
}];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章