Re: Adding/removing managed objects: how to know the maximum index?
Re: Adding/removing managed objects: how to know the maximum index?
- Subject: Re: Adding/removing managed objects: how to know the maximum index?
- From: David Spooner <email@hidden>
- Date: Wed, 14 Nov 2007 17:32:47 -0700
On 14-Nov-07, at 3:47 PM, Arthur C. wrote:
My Core Data managed objects (instances) all have their own index.
Naturally, when I add an object, I want to set its index to the
highest index value so far, + 1. This should be done in -
awakeFromInsert.
However, when I perform a fetch request from there, a second (new)
item appears in the table (instead of just one). This can't be right.
So, the question is how to keep track of the maximum index in a
correct way.
Should I maintain a class variable for the maximum index (updated
on awakeFromFetch / -Insert)? If so, how do I keep track of removed
objects (say when the object with the highest index gets removed)?
Suggestions appreciated.
Arthur,
I would add to the data model an entity (say Info) to maintain the
maximum index. If I didn't need my object indices to be contiguous
then I would simply increment the index on insertion and do nothing
on deletion (rather than updating the indices of the remaining
objects and decrementing the maximum index). If I didn't mind having
gaps in the indices but wanted to reuse them when possible then I
would add a set of unused indices as a to-many relation of the Info
entity. These properties could be transient, but I think its much
simpler to make them persistent.
Cheers,
dave
Best regards,
Arthur C.
_______________________________________________
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