• 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
Re: Determine keys used in NSPredicate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determine keys used in NSPredicate


  • Subject: Re: Determine keys used in NSPredicate
  • From: Ken Thomases <email@hidden>
  • Date: Sun, 20 Oct 2013 01:08:54 -0500

On Oct 20, 2013, at 12:27 AM, Trygve Inda wrote:

> My question is: After I have an NSPredicate built by the user with the
> Predicate editor, how can determine the keys that the NSPredicate uses?

You need to traverse the hierarchy of objects represented by the predicate.

The NSPredicate you have is actually an NSCompoundPredicate or an NSComparisonPredicate.  Use -isKindOfClass: to figure out which.  For the former, iterate over its -subpredicates and recursively apply this algorithm to each.  For the latter, examine the -leftExpression and -rightExpression.

For each expression, query its -expressionType.  If it's NSKeyPathExpressionType, obtain its -keyPath, parse it into its individual keys, and compare against the key of interest.  For the other types, you need to figure out which properties to query to get the appropriate sub-expressions and even sub-predicates to recurse further.  The documentation doesn't lay this all out quite as explicitly as one might like, but you can figure it out by examining the convenience constructors.  If in doubt, some trial and error should make it clear – querying properties which are not appropriate for a given type raises an exception.

Regards,
Ken


_______________________________________________

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


References: 
 >Re: Determine keys used in NSPredicate (From: Trygve Inda <email@hidden>)

  • Prev by Date: Re: Determine keys used in NSPredicate
  • Next by Date: Re: Setting key equivalent for menus depending on window
  • Previous by thread: Re: Determine keys used in NSPredicate
  • Next by thread: Re: Determine keys used in NSPredicate
  • Index(es):
    • Date
    • Thread