Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding/removing managed objects: how to know the maximum index?




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:
http://lists.apple.com/mailman/options/cocoa-dev/sachin.tulla% 40moschip.com


This email sent to email@hidden
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Adding/removing managed objects: how to know the maximum index? (From: Arthur C. <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.