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 (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to