• 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
NSPredicate and Arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPredicate and Arrays


  • Subject: NSPredicate and Arrays
  • From: "Jake Carter" <email@hidden>
  • Date: Mon, 31 Mar 2008 12:41:39 -0700

Hey Guys,
I'm trying to use NSPredicate to filter an array. Here's the structure of my
array

ArrayOfFoos:
    Foo: (Custom Object)
        Bars: (NSArray *)            Bar: (Custom Object)
                Baz = 1 (int Property on custom object)
            Bar:
                Baz = 3
        ...
    Foo:        Bars:
            Bar:
                Baz = 2
            Bar:
                Baz = 1
        ...
...

and
So what I want to do is pull out all Foos who have a baz == 1.

I've tried

NSPredicate *p = [NSPredicate predicateWithFormat:@"bars.baz == 1"];
NSMutableArray *ma = [NSMutableArray arrayWithArray:[arrayOfFoos
filteredArrayUsingPredicate:p]];

which obviously won't work because the bars don't have a baz property
because it's an array.

I've also tried adding [] so that it know it's an array, but that didn't
work either...

NSPredicate *p = [NSPredicate predicateWithFormat:@"bars[].baz == 1"];
NSMutableArray *ma = [NSMutableArray arrayWithArray:[arrayOfFoos
filteredArrayUsingPredicate:p]];

I'm not sure what expression to use to denote that I want the predicate to
drill down in to each bar to look for the baz.

I hope this make sense. Any help would be great.

Thanks,

:// Jake
_______________________________________________

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

  • Follow-Ups:
    • Re: NSPredicate and Arrays
      • From: Keary Suska <email@hidden>
  • Prev by Date: Problem with setting color in NSBitmapImageRep
  • Next by Date: libpq prepared statement
  • Previous by thread: Re: Problem with setting color in NSBitmapImageRep
  • Next by thread: Re: NSPredicate and Arrays
  • Index(es):
    • Date
    • Thread