Mailing Lists: Apple Mailing Lists

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

Predicate expressions



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:
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.