Hi everyone,

I've figured out a way to do an "date in the last X days" predicate, but I'm 
having to do it as a block predicate.  This works fine, but I've run up against 
another situation:  NSBlockPredicates don't support archiving.  This is a 
problem, since I need to store this predicate in a CoreData store.

Basically, I'm trying to do have a predicate like:

NSPredicate * p = [NSPredicate predicateWithFormat:@"%@ >= NOW() - 86400", 
aDate];

If that actually worked, it would return true if "aDate" is newer than 1 day 
ago (86400 seconds = 1 day).

I can do this with a block predicate:

NSTimeInterval timeAgo = -86400;
NSPredicate * p = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, 
NSDictionary * bindings) {
  NSDate * cutoff = [NSDate dateWithTimeIntervalSinceNow:timeAgo];
  return ([cutoff laterDate:evaluatedObject] == evaluatedObject);
}];

....except that this can't be archived.

Is there a way around this?  I'm not aware of any function like "NOW()" that 
can be used in an NSPredicate.

The only other way I've thought of is to use a substitution variable, something 
like $NOW, and then create my predicate dynamically using 
-predicateWithSubstitutionVariables:.  This could work, except that some of my 
predicates get evaluated very frequently, and I'm worried about that being too 
costly.  (However, if it's the only alternative, then I have no choice).

Thoughts?  Suggestions?

Thanks!

Dave

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to