• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: wrapping my head around NSPredicate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wrapping my head around NSPredicate


  • Subject: Re: wrapping my head around NSPredicate
  • From: SA Dev <email@hidden>
  • Date: Fri, 29 Jul 2005 16:04:05 -0400

Zameer:

I'm noticing something sticking out like a sore thumb that I thought was worth mentioning. I notice your keys start with upper- case letters. If this is just an example, that's fine, but you should be aware that Core Data and Cocoa Bindings both rely on Key-Value Coding and Key-Value Observing, which in turn requires keys to be KVC/ KVO compliant. This means that your keys (and setter/getter method names) should all start with lower-case letters. For good practice, so should your variables, but that's not a requirement.

So to be KVC/KVO compliant (and to be able to provide code examples that look like the rest of the Objective-C world for easy reading):

id value1 = [namePK valueForKey:@"firstName"];
id value2 = [namePK valueForKey:@"lastName"];

I don't know if this would cause your problems, but it's bound to cause *some* problems *somewhere*. :-)






On Jul 29, 2005, at 12:17 PM, Zameer Andani wrote:

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:
40silentalcove.net


This email sent to email@hidden


_______________________________________________ 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
References: 
 >RE: wrapping my head around NSPredicate (From: "Zameer Andani" <email@hidden>)

  • Prev by Date: Re: list society and of discussion threads
  • Next by Date: Re: NSWorkspace
  • Previous by thread: Re: wrapping my head around NSPredicate
  • Next by thread: Cocoa runtime VM?
  • Index(es):
    • Date
    • Thread