Re: [NSPredicate predicateWithFormat:]
Re: [NSPredicate predicateWithFormat:]
- Subject: Re: [NSPredicate predicateWithFormat:]
- From: Corbin Dunn <email@hidden>
- Date: Tue, 28 Jun 2005 08:23:06 -0700
On Jun 28, 2005, at 8:15 AM, Hamish Allan wrote:
Hi,
Why is it that when I try:
NSPredicate *predicate = [NSPredicate
predicateWithFormat:@"*=='foo.pdf'"];
I get:
2005-06-28 16:04:28.621 MDTest[4100] An uncaught exception was raised
2005-06-28 16:04:28.636 MDTest[4100] Unable to parse the format
string "*=='foo.pdf'"
2005-06-28 16:04:28.651 MDTest[4100] *** Uncaught exception:
<NSInvalidArgumentException> Unable to parse the format string
"*=='foo.pdf'"
whereas I can type, as a 'Raw Query' into Finder:
*=='foo.pdf'
*='foo.pdf'
*==foo.pdf
all of which work, or I can use:
NSPredicate *predicate = [NSComparisonPredicate
predicateWithLeftExpression:[NSExpression
expressionForKeyPath:@"*"]
rightExpression:[NSExpression
expressionForConstantValue:@"foo.pdf"]
modifier: NSDirectPredicateModifier
type: NSLikePredicateOperatorType
options: (NSCaseInsensitivePredicateOption |
NSDiacriticInsensitivePredicateOption)];
which also works.
Does the Finder use its own mechanism to parse the Spotlight query?
Unfortunately, the predicate parser doesn't support certain
constructs (yet). The Spotlighter example app goes over this. Here is
some of the code:
// Create a compound predicate that searches for any keypath
which has a value like the search key. This broadens the search
results to include things such as the author, title, and other
attributes not including the content. This is done in code for two
reasons: 1. The predicate parser does not yet support "* = Foo" type
of parsing, and 2. It is an example of creating a predicate in code,
which is much "safer" than using a search string.
unsigned options = (NSCaseInsensitivePredicateOption|
NSDiacriticInsensitivePredicateOption);
NSPredicate *compPred = [NSComparisonPredicate
predicateWithLeftExpression:[NSExpression
expressionForKeyPath:@"*"]
rightExpression:[NSExpression
expressionForConstantValue:_searchKey]
modifier:NSDirectPredicateModifier
type:NSLikePredicateOperatorType
options:options];
--corbin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden