• 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: Object Identity Tests in Core Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Object Identity Tests in Core Data


  • Subject: Re: Object Identity Tests in Core Data
  • From: Niko Matsakis <email@hidden>
  • Date: Wed, 31 Aug 2005 11:10:16 +0200

I guess it's that I didn't find documentation on what kinds of types are available in predicates.


<http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/ Articles/cdFetching.html#//apple_ref/doc/uid/TP40002484/ DontLinkElementID_18>

Yes, I read this before I posted, and also the Predicate Programming Guide. To be honest, the section here on comparing to self left me more confused then when I started.


What really confused me was this line in the code example under Retrieving Specific objects:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self == %@", targetObject];

In case anyone cares, this is what went though my head after reading this:


1. Okay, does this mean there is a special property called "self" on every managed object? Thinking about this now, I realize that perhaps this comes for free using Key Value Coding because NSObject defines a self method?

2. I was confused because I didn't know what type targetObject was. If it's an NSManagedObject*, which makes sense, then why are you doing the fetch? You already have the answer!

3. Why is it using string substitution? Won't this generate something like:
"self == 'NSManagedObject instance at 0x55555'"
where the string is whatever is returned by [targetObject description]? I would expect it to use bound variables rather than string substitution. The predicate guide says "%@" is substitution for a value, usually a string value; so I suppose == may not indicate string expansion, but you really have to dig around the predicates guide to find that and it's a throwaway sentence which could use to be expanded upon.


4. Then it mentions the IN operator, but doesn't show an example. How would I go about doing that? Could I rewrite the example like so:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self IN %@", targetObjectSet];

where targetObjectSet is an NSSet* instance.

Anyway, I don't mean to be complaining per se, just pointing out how I got confused. As I said earlier, I think Core Data is great and the documentation is pretty decent.

I'm still not 100% convinced that there is only one NSManagedObject instance for each object in my Core Data database; it seems like it should work that way, but I didn't really see that in the documentation.


<http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/ Articles/cdFaultUniquing.html#//apple_ref/doc/uid/TP30001202-185502- TPXREF148>

I stand corrected on this point; now that I see this I do remember reading it.



Niko _______________________________________________ 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
  • Follow-Ups:
    • Re: Object Identity Tests in Core Data
      • From: mmalcolm crawford <email@hidden>
References: 
 >Object Identity Tests in Core Data (From: Niko Matsakis <email@hidden>)
 >Re: Object Identity Tests in Core Data (From: Chris Hanson <email@hidden>)
 >Re: Object Identity Tests in Core Data (From: Niko Matsakis <email@hidden>)
 >Re: Object Identity Tests in Core Data (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: CoreData: To Many Relationships, what type?
  • Next by Date: Re: Object Identity Tests in Core Data
  • Previous by thread: Re: Object Identity Tests in Core Data
  • Next by thread: Re: Object Identity Tests in Core Data
  • Index(es):
    • Date
    • Thread