Re: Creating a predicate based on objectID in CoreData?
Re: Creating a predicate based on objectID in CoreData?
- Subject: Re: Creating a predicate based on objectID in CoreData?
- From: Bill Cheeseman <email@hidden>
- Date: Sat, 06 Aug 2005 06:52:06 -0400
on 2005-08-05 9:19 PM, Colin Cornaby at email@hidden wrote:
> I came up with the idea of searching based on the owners object id,
> and compare against the specific owner object id I want to find. Here
> is how I did my predicate:
>
> NSPredicate *predicate = [NSPredicate
> predicateWithFormat:@"self.owner.objectID == %@",
> [[[ownerObjectBeingUsed objectID] URIRepresentation] path]];
>
> This doesn't work though and I'm getting back nothing.
To use the objectID in my app, I create a transient string attribute in my
model called uniqueID. In a subclass of NSManagedObject I implement an
accessor method, -uniqueID, that returns the objectID converted to an
NSString. I can compare the string versions of uniqueID to equate two
instances. You may not need a transient attribute for this in your
situation, given mmalc's reference, but in mine a transient attribute makes
it particularly easy to get at the objectID, which I need for other reasons
as a unique identifier for any entity instance.
Here's how I convert the objectID to a string:
[[[self objectID] URIRepresentation] absoluteString]
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
PreFab Software - http://www.prefab.com/scripting.html
The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
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