• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Adding/removing managed objects: how to know the maximum index?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread 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: Sachin Kumar Tulla <email@hidden>
  • Date: Thu, 15 Nov 2007 10:24:50 +0530


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:
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:
This email sent to email@hidden


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

  • Prev by Date: Re: After upgrade to leopard: "principalClass is nil" while loading preferencesPane
  • Next by Date: Re: Adding/removing managed objects: how to know the maximum index?
  • Previous by thread: Re: Adding/removing managed objects: how to know the maximum index?
  • Next by thread: Re: Adding/removing managed objects: how to know the maximum index?
  • Index(es):
    • Date
    • Thread