Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPredicate and Arrays



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.