• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Archiving NSBlockPredicate and NSPredicate date functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Archiving NSBlockPredicate and NSPredicate date functions


  • Subject: Archiving NSBlockPredicate and NSPredicate date functions
  • From: Dave DeLong <email@hidden>
  • Date: Wed, 28 Apr 2010 14:13:32 -0600

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 (email@hidden)

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:

This email sent to email@hidden

  • Prev by Date: Re: NSCalendar date calculation anomaly
  • Next by Date: Re: CFUUID question
  • Previous by thread: Re: CFUUID question
  • Next by thread: Field editors in layer-hosting views
  • Index(es):
    • Date
    • Thread