Re: Need help with predicate format
Re: Need help with predicate format
- Subject: Re: Need help with predicate format
- From: Fabian <email@hidden>
- Date: Mon, 28 Jul 2008 10:02:56 +0200
Thanks. Maybe I should have made myself a little more clear. I don't
want to iterate over the array, but filter the array using a
NSPredicate.
I'm looking at the Predicate Programming Guide, which only gives basic
guidance, and the docs for NSExpression. It has several class methods
that "sound right" (expressionForEvaluatedObject:,
expressionForAggregate:,
expressionForSubquery:usingIteratorVariable:predicate:,
expressionForFunction:arguments:) but provides no examples how to use
them. Unfortunately Google has very little to say on this subject too.
To repeat the problem: I want to check the value of all keys in every
dictionary contained by an array and see if they match my search
string.
A workaround to compensate for my syntax ignorance would be to add a
new instance method to my custom class that simply return all the
values I want to check in a single array. Then I could query it with a
simple single-relationship predicate:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(%@ IN
values, searchString)"];
NSArray filteredArray = [myArray filteredArrayUsingPredicate:predicate];
But somehow I believe there is a more direct way to do this, without
having to add a new "helper method" to my class? I'm perfectly happy
with a 10.5 only solution.
Thanks.
On Mon, Jul 28, 2008 at 8:30 AM, Graham Cox <email@hidden> wrote:
>
> On 28 Jul 2008, at 1:52 pm, Omar Qazi wrote:
>
>> To be honest, I don't know if this will work, since I don't know if
>> containsObject is checking if the argument is a pointer to an object in the
>> array, or if it is equal to the object, but it's better than nothing, I
>> guess.
>
>
> From the docs:
>
> containsObject:
> Returns a Boolean value that indicates whether a given object is present in
> the receiver.
>
> - (BOOL)containsObject:(id)anObject
>
> Parameters
>
> anObject
> An object.
>
> Return Value
> YES if anObject is present in the receiver, otherwise NO.
>
> Discussion
> This method determines whether anObject is present in the receiver by
> sending an isEqual: message to each of the receiver's objects (and passing
> anObject as the parameter to each isEqual: message).
>
> Availability
> • Available in Mac OS X v10.0 and later.
>
>
>
>
> cheers, Graham
_______________________________________________
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