Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top