RE: wrapping my head around NSPredicate
RE: wrapping my head around NSPredicate
- Subject: RE: wrapping my head around NSPredicate
- From: "Zameer Andani" <email@hidden>
- Date: Fri, 29 Jul 2005 09:17:06 -0700
- Thread-topic: wrapping my head around NSPredicate
Thanks Charilaos, and list...
I am trying to match NamePK to a particular instance of classA. i realize the method is not complete as I still need to return the NSPredicate*
What I'm trying to avoid is having to write the following (which is what i have right now), as it is extremely coupled with the layout of ClassA:
id value1 = [NamePK valueForKey:@"FirstName"];
id value2 = [NamePK valueForKey:@"LastName"];
[predicateFormat appendFormat: @"NamePK.FirstName == %@ And NamePK.LastName == %@", value1, value2];
-----Original Message-----
From: Charilaos Skiadas [mailto:email@hidden]
Sent: Friday, July 29, 2005 12:58 AM
To: Zameer Andani
Cc: Cocoa-Dev Apple
Subject: Re: wrapping my head around NSPredicate
On Jul 28, 2005, at 11:52 AM, Zameer Andani wrote:
> Can someone perhaps shed some light in how to create a predicate
> that does an object comparison?
>
> For instance, if I had the following:
>
> @interface classA
> {
> NSDictionary *representation; //initialized with [FirstName
> ==> "Zameer", LastName ==> "Andani"]
> }
>
> @interface classB
> {
> NSDictionary *representation; //initialized with [NamePK ==>
> classA]
> }
>
> -(NSPredicate *)predicate
> {
> NSMutableString *predicateFormat = [[NSString alloc] init];
>
> [predicateFormat appendFormat: @"NamePK == ???"];
> }
>
> am I allowed to do this, or do I need to fully qualify the string
> to something like:
>
> "NamePK.FirstName Matches "Zameer"
(First off, the above method is of course not finished, since it does
not return an NSPredicate instance)
First question: What are the ???? for?
Second question: What are you trying to match? all occurrences where
the value of NamePK is a particular instance of classA, namely
determined by the ????, or all occurrences where the first name of
the value of NamePK, is "Zameer"?
If you want the former, then you could probably achieve it, supposing
the instance you are trying to match is say "instanceA" by:
-(NSPredicate *)predicate
{
NSPredicate *thePredicate = [NSPredicate
predicateWithFormat:@"NamePK == %@" argumentArray:[NSArray
arrayWithObject:instanceA]];
return thePredicate;
}
If you can explain to us in more detail what you are trying to
accomplish, then maybe we can offer some more detailed help.
>
> Zameer
>
HTH,
Haris
_______________________________________________
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