Re: Validating unique objects in CoreData
Re: Validating unique objects in CoreData
- Subject: Re: Validating unique objects in CoreData
- From: Chris Hanson <email@hidden>
- Date: Sun, 14 Feb 2010 12:29:13 -0800
On Feb 13, 2010, at 4:32 PM, Sean McBride wrote:
> 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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden