Skip navigation.
 
mlRe: NSPredicate and square brackets
FROM : slasktrattenator
DATE : Thu Nov 29 17:12:10 2007

Thank you, that worked. I should have read up on the syntax before posting.

On Nov 29, 2007 5:00 PM, $B!g(B <<email_removed>> wrote:

>
> Il giorno 29/nov/07, alle ore 14:17, <email_removed> ha
> scritto:
>
> > NSString *value = [NSString stringWithFormat:@"name MATCHES '%@'",
> > item];
> >
> > NSPredicate *predicate = [NSPredicate predicateWithValue:value];
>
> The compiler warning might have tipped off the fact you are doing
> something completely wrong.
> +predicateWithValue's signature is:
>
> + (id) predicateWithValue:(BOOL) value;
>
> and produces a predicate which is always true (YES) or always false
> (NO). You are passing a nonzero pointer, which is cast to an integer
> (with an irate warning!), and works like YES since it is nonzero.
>
> Also:
>
> > NSString *item = @"[unknown]";
> >
> > NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name
> > MATCHES %@",
> > item];
> >
> > nameArray = [nameArray filteredArrayUsingPredicate:predicate]; //
> > filtered
> > array does not include object @"[unknown]"
>
> Of course it doesn't, because [@"unknown" name] is not @"unknown". You
> probably want self rather than name, and you probably don't want to
> use MATCHES since it requires a regular expression (and [] are special
> characters in a regular expression).
>
> Look at the Predicate Programming Guide, especially
> <file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html
>  > for the predicate syntax.
>
> In this particular case, you probably want:
>
> NSPredicate* p = [NSPredicate predicateWithFormat:@"self == %@", item];
>
>  - $B!g(B
>
>

Related mailsAuthorDate
mlNSPredicate and square brackets slasktrattenator Nov 29, 03:28
mlRe: NSPredicate and square brackets slasktrattenator Nov 29, 14:17
mlRe: NSPredicate and square brackets slasktrattenator Nov 29, 17:12