predicateWithFormat: argumentArray:
predicateWithFormat: argumentArray:
- Subject: predicateWithFormat: argumentArray:
- From: Nicholas Crosbie <email@hidden>
- Date: Fri, 4 Nov 2005 12:26:14 +1100 (EST)
Hi list,
the following code returns "firstArray" filtered by
the first element of "secondArray" (value = 3). How
--
using a predicate approach -- to filter firstArray
by ALL elements of secondArray.
i.e. firstArray would contain 4 elements (3, 6, 9,
12)
after being filtered by secondArray.
- NDC
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSMutableArray *firstArray;
NSMutableArray *secondArray;
int i;
NSNumber *newNumber;
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]
init];
firstArray = [[NSMutableArray alloc] init];
secondArray = [[NSMutableArray alloc] init];
for ( i=1; i<10; i++) {
newNumber = [[NSNumber alloc] initWithInt:(i *
3)];
[firstArray addObject:newNumber];
[newNumber release];
}
for ( i=1; i<5; i++) {
newNumber = [[NSNumber alloc] initWithInt:(i *
3)];
[secondArray addObject:newNumber];
[newNumber release];
}
NSLog(@"%@",firstArray);
printf ("\n");
NSLog(@"%@",secondArray);
NSPredicate *thePredicate = [NSPredicate
predicateWithFormat:@"SELF ==
%@"argumentArray:secondArray];
;
[firstArray filterUsingPredicate:thePredicate];
printf ("\n");
NSLog(@"%@",firstArray);
[firstArray release];
[secondArray release];
[pool release];
return 0;
}
____________________________________________________
Do you Yahoo!?
Yahoo! on your mobile - Mail, Messenger, Movies and more!
http://au.mobile.yahoo.com/mweb/index.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden