Chris Hanson (c...@me.com) on 2010-02-14 15:29 said:
>> I have
>> found NSManagedObject's objectID method largely useless since, as the
>> docs say, "if the receiver has not yet been saved, the object ID is a
>> temporary value that will change when the object is saved”.
>
>These aren’t as useless for your own use as they may seem at first glance.
>
>For example, if you need to track objects by ID (say as a dictionary
>key) you should be able to update your tracking upon save to use the
>objects’ permanent IDs.
>
>Also, if you need to work with permanent IDs, you can request specific
>objects be assigned permanent IDs prior to save using -
>[NSManagedObjectContext obtainPermanentIDsForObjects:error:].
>
>> I have also found
>> it odd that Core Data behaves like this, but I guess there is some SQL/
>> database reason for it all…
>
>One hint to recognizing this is that the method to obtain permanent IDs
>can fail and return an error.
>
>Obtaining permanent IDs for objects requires a transaction, because in
>non-atomic persistent stores (e.g. the SQLite persistent store) you may
>have multiple requests happening at a single time against the same store.
Chris,
Thanks for these thoughts.
Still, it seems quite cumbersome compared to just adding one's own
'uuid' attribute.
What are the pros and cons of each technique?
It seems using one's own 'uuid' is far simpler. No need to watch for
saves occurring, no need to test this case, no need to deal with two
kinds of IDs (temp and perm), no need to convert between the two, no
need for a backup plan if the conversion fails.
OTOH, I guess it takes several bytes more per managed object. This
could add up if you have many many objects. I understand that searching
by one's own uuid is slower. It's also distasteful to re-invent the wheel.
Any other pros/cons?
Cheers,
Sean
--
"First they ignore you, then they laugh at you, then they fight you,
then you win." - Gandhi
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com