Hi Kirk,
The variable wildcardString would contain a string such as *GREEN* for a
wildcard search to include files with that name, and for simplicity's sake a
string like !*GREEN* for those that wish to exclude files that contain the
string.
Here is a sample bit of code..
BOOL foundStar = NO;
BOOL notPredicate = NO;
NSRange firstNotStar = [wildcardString rangeOfString:@"!*"];
if (firstNotStar.location != NSNotFound) {
notPredicate = YES;
}
NSRange firstStar = [wildcardString rangeOfString:@"*"];
if (firstStar.location != NSNotFound) {
foundStar = YES;
if (notPredicate) {
NSString *arg = [wildcardString substringFromIndex:1];
[self setPredicate:[NSPredicate predicateWithFormat:@"SELF NOT
like[c] %@", arg]];
} else
[self setPredicate:[NSPredicate predicateWithFormat:@"SELF
like[c] %@", wildcardString]];
}
If the "notPredicate" is true, the "!" character is trimmed from the front of
the string, before it is passed to the predicate.
I've replaced the "not" predicate with all sorts of combinations. I get a
NSInvalidArgumentException the moment the NSPredicate is instantiated.
Bob..
On Mar 21, 2010, at 11:31 AM, Kirk Kerekes wrote:
> I suggest that you need to provide the actual code you are using to generate
> the NSPredicate, because what you are wanting to do just isn't that hard.
>
> The problem may not be in the predicate format string.
>
> I would have used @"NOT CONTAINS[cd] %@" as my first pass, and been quite
> surprised if it didn't work. NSPredicate has its quirks, but the
> straightforward stuff tends to be... straightforward.
>
>
_______________________________________________
Cocoa-dev mailing list ([email protected])
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 [email protected]