Reputation: 95
I'm making an app where users can post objects which contain an NSDate property. I want to be able to run a piece of code that checks whether the current date is after the objects date property, and then delete those objects. I'm using Parse to hold all of the objects.
I know that
NSDate *now = [NSDate dateWithTimeIntervalSinceNow:-3600];
PFQuery *query = [PFQuery queryWithClassName:@"Post"];
[query whereKey:@"Date2" equalTo:now];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (PFObject *object in objects) {
[object deleteInBackground];
}
}
}];
will check and delete the objects that are an hour before the current date. But how can I make sure every object before the current date is deleted, and not just an hour before.
Upvotes: 0
Views: 148
Reputation: 53112
The problem is that you're using equalTo:
This:
[query whereKey:@"Date2" equalTo:now];
Should be:
[query whereKey:@"Date2" lessThanOrEqualTo:now];
Otherwise, you only get objects that match the date exactly. Since this doesn't happen very often, you're returning no results.
Upvotes: 2