• 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: Core Data, transient ivars and undo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data, transient ivars and undo


  • Subject: Re: Core Data, transient ivars and undo
  • From: email@hidden
  • Date: Sun, 12 Feb 2006 15:09:57 -0800

Christiaan Hofman wrote:

I am very much confused about undo in Core Data, in particular when it comes to "transient" values and other dependent state information. AFAICS the transient value or state info is not updated in any way in undo, which can easily lead to inconsistent states in CD apps. How should I handle this in general?

For example a "transient" value stored in an ivar. Eg for a non- standard attribute, which is stored in the MOC as data, but has an ivar representation in a NSManagedObject subclass. Usually, you interact with the transient value (ivar) rather than the underlying CD value. However it is the data in the MOC that is changed in undo, and only that. So you get an inconsistent state. Writing (KVC compliant) accessors for the underlying data does not help, as they are not called by undo.

In the docs and example projects like CoreRecipes many accessors seem to have this flaw. Eg the "bounds" example in "Non-Standard Attributes" section of the Core Data Programming Guide. Here the bounds ivar and the boundsAsData atribute should always be synchronized. However, AFAICS, if I would undo setting (changing) the bounds, only the boundsAsData attribute is changed, giving me an inconsistent state. This seems to me a bug in CD, or at least in the docs and the examples, as nothing is mentioned about it.
Perhaps [self setKey:@"boundsAsData" triggerChangeNotificationForDependentKeys:[NSArray arrayWithObject:@"bounds"]] ?
Since, bounds is not "known" by core data that it is related to boundsAsData, it needs to be told they are, I beleive that telling core data to generate a change note when boundsAsData changes to also notify observers of the change to bounds, would call the getter in your bounds method, and reverse the change.... have you tried this?


So my question is: how should I handle dependent state information in general so that undo works properly? Do I need to observe MOM keys for values on which the state of some object depends? Or should I explicitly register undo operations when I change an ivar such as the bounds in the example? It would have been helpful (I would even say required) that these issues were mentioned in the docs, especially as undo is automatic with little information and control about what's going on behind the scene.
I think setKey: triggerChangeNotificationForDependentKeys may be your answer. Called in +initialize it may work for your particular difficulty.

Christiaan


_______________________________________________ MacOSX-dev mailing list email@hidden http://www.omnigroup.com/mailman/listinfo/macosx-dev

Andre email@hidden



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Who's launching me?
  • Next by Date: Re: Who's launching me?
  • Previous by thread: Re: Force an Application to crash : possible ?
  • Next by thread: Re: Core Data, transient ivars and undo
  • Index(es):
    • Date
    • Thread