Re: NSPredicate & Editor questions
Re: NSPredicate & Editor questions
- Subject: Re: NSPredicate & Editor questions
- From: Peter Ammon <email@hidden>
- Date: Wed, 12 Aug 2009 15:02:47 -0700
On Aug 11, 2009, at 5:51 PM, Dave DeLong wrote:
Hey everyone,
Hi Dave!
I'm about to embark on understanding NSRule/PredicateEditors but
before I get too deep into the code, I wanted to ask a couple
questions.
I'm hoping to create an interface whereby the user can create an
NSPredicate and then come back and edit it later. From what I've
understood from the documentation and PredicateEditorSample, it
seems that the appropriate way to do this would be to construct an
NSCompoundPredicate from the editor. That way when the user goes to
edit the predicate, I can easily break it up into its constituent
parts by using the -subpredicates method of NSCompoundPredicate. Is
that correct?
You certainly can break it up if you want. However, most tasks do not
require you to do so. For example, setting it as the filter predicate
on an NSArrayController, evaluating it against some object, or
persisting it to disk do not require you to break it up.
If that is correct, would I then have to determine with
NSPredicateEditorRowTemplate I'd need to use by examining the
subpredicate itself?
NSPredicateEditor does this work for you. You can set an NSPredicate
directly on an NSPredicateEditor via [editor
setObjectValue:somePredicate], and it will figure out which templates
to use, like so:
1) It calls matchForPredicate: on each template, and uses the template
that returns the highest match.
2) It calls displayableSubpredicatesOfPredicate: on the winning
template to determine what NSPredicates should become subrows. The
default implementation returns the subpredicates of a compound
predicate, and nil for a simple predicate.
This process is recursive, so NSPredicateEditor does the work of
picking apart compound predicates. If you subclass
NSPredicateEditorRowTemplate, you may want to override
matchForPredicate: to identify which predicates your template handles,
but you should not need to pick apart the predicate yourself.
Hope this helps,
-Peter
_______________________________________________
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