FROM : Jake Carter
DATE : Mon Mar 31 21:41:39 2008
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
DATE : Mon Mar 31 21:41:39 2008
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
| Related mails | Author | Date |
|---|---|---|
| Jake Carter | Mar 31, 21:41 | |
| Keary Suska | Mar 31, 22:43 |






Cocoa mail archive

