Re: Trouble using ANY operator in an NSArrayController search predicate
Re: Trouble using ANY operator in an NSArrayController search predicate
- Subject: Re: Trouble using ANY operator in an NSArrayController search predicate
- From: Greg Herlihy <email@hidden>
- Date: Sat, 20 May 2006 06:57:34 -0700
- Thread-topic: Trouble using ANY operator in an NSArrayController search predicate
The CONTAINS operator tests whether an array contains a specific value - so
as an array operator CONTAINS performs strictly value comparisons. So
CONTAINS returns true only when the search string and the string value
exactly match - just as "key contains[cd] $value" will only be true for a
key that exactly matches $value.
More sophisticated string searches (such as partial string comparisons)
require one of the string operators. Of which MATCHES is the most capable
(and can deal with matching carriage returns). The MATCHES operator cannot
be used in a fetch request against an SQL store, however, but it can be used
to filter an array of fetched objects.
Greg
On 5/20/06 5:02 AM, "Jim Correia" <email@hidden> wrote:
> On May 20, 2006, at 3:56 AM, Greg Herlihy wrote:
>
>> The problem is apparently that CONTAINS is not a string operator in
>> predicate comparisons. According to the BNF section of the Predicates
>> Programming Guide the four string operators are BEGINSWITH,
>> ENDSWITH, LIKE
>> and MATCHES. So it looks like the Predicates Programming Guide
>> mistakenly
>> includes CONTAINS (which is apparently an array operator) as a string
>> operator in its "Predicate String Format Syntax" section.
>
> In the operations section of the doc, it says:
>
> CONTAINS and IN serve both as aggregate operators and string
> operators, depending on the types of their arguments.
>
> The auto-generated test UI when you drag an entity over to IB uses
> predicates of the form "key contains[cd] $value" for the search
> field. Based on that, my working assumption is that it should work.
>
>> Anyway, I have verified that the following predicate successfully
>> matches
>> the partial course name ("phy") against the full course name
>> ("physics")
>> stored in the dictionary.
>>
>> NSPredicate *predicate = [NSPredicate predicateWithFormat: @"ANY
>> courses.name LIKE[cd] %@", @"*phy*"];
>
> The problem here is that LIKE "*string*" isn't a complete replacement
> for CONTAINS "string" since * doesn't match across line breaks.
_______________________________________________
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