NSManagedObjectID best practices?
NSManagedObjectID best practices?
- Subject: NSManagedObjectID best practices?
- From: Jesse Grosjean <email@hidden>
- Date: Tue, 20 Dec 2005 17:11:41 -0500
I'm trying to figure out the best way to use NSManagedObjectID. I
love having automatic unique ids for my objects, but I'm not finding
clean ways to work around the fact that objects start out with
temporary ids then later change to a different persistent id when
saved. First here are some cases where I make use of
NSManagedObjectID's.
- I use them to record the selected objects in my outline view in
user defaults so that they can be restored when the document is
reopened.
- I use them as link identifiers for creating hyperlinks between my
objects.
- I use them to implement NSUniqueIDSpecifier's for applescript support.
The problem is that in all of these cases problems happen when I pass
out a temporary ID that later changes into a permanent ID, since the
temporary ID becomes invalid. So I have a few questions...
First is it ok to use NSManagedObjectID's this way, or are they not
really intended to be used by application code? And if they are
intended to be used by application code what's a good strategy for
handling the changeover from temporary to persistent ids? One
possibility is to always save the context before accessing and ID so
that only persistent ids are ever used. That seems to work great, but
then you have to do extra work to avoid performance problems. Another
option is to maintain a mapping between temporary and persistent ID's
so that temporary ID's can still be used after the context is saved.
That would avoid the performance problem, but seems a bit messy.
Thanks for any suggestions.
Jesse
_______________________________________________
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