Predicate expressions
Predicate expressions
- Subject: Predicate expressions
- From: Fabian <email@hidden>
- Date: Sat, 31 May 2008 22:57:56 +0200
Hello,
I'm trying to figure out how to use NSExpressions in a predicate but
find the documentation a bit deficient.
Here is what I want to do: I have an array - array A - containing
objects with a "title" and "subtitle" property. I want to filter this
array so it only contains the objects in array B. The example below
demonstrates what I want to achieve, but lacks in precision. It only
checks the presence of the title and subtitle in array B, so the pair
could just as well belong to two different objects. I need to know
that both the title and subtitle of object X in array A matches the
title and subtitle of object Y in array B. Will a NSExpression let me
do this?
NSArray *arrayB = [self getObjects] ;
NSArray *titles = [arrayB arrayByApplyingSelector:@selector(title)];
NSArray *subtitles = [arrayB arrayByApplyingSelector:@selector(subtitle)];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(title IN
%@) AND (subtitle IN %@)", titles, subtitles];
NSArray *result = [arrayA filteredArrayUsingPredicate:predicate];
Regards,
Fabian
_______________________________________________
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