• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSPredicate and square brackets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPredicate and square brackets


  • Subject: Re: NSPredicate and square brackets
  • From: email@hidden
  • Date: Thu, 29 Nov 2007 17:12:10 +0100

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

On Nov 29, 2007 5:00 PM, ∞ <email@hidden> wrote:

>
> Il giorno 29/nov/07, alle ore 14:17, email@hidden 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];
>
>  - ∞
>
>
_______________________________________________

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

References: 
 >NSPredicate and square brackets (From: email@hidden)
 >Re: NSPredicate and square brackets (From: email@hidden)

  • Prev by Date: Re: Dev tools private frameworks.
  • Next by Date: Re: Leopard NSTableView Cell and single click editing
  • Previous by thread: Re: NSPredicate and square brackets
  • Next by thread: removing item from NSTreeController or NSOutlineView
  • Index(es):
    • Date
    • Thread