1 Comment to “An Eternal Headache: Core Data, Undo and Files”

  1. Jonathan Mitchell

    Nov 3rd, 2009

    Kenneth

    I agree that core data is a powerful technology though it is undeniably complex.

    I have found that the best approach with core data is to remember what it is – an object graph persistence framework. The more you can let core data itself manage data the better.

    It seems likely that your choice of using a document bundle set you on something of a collision course with core data. I use NSData representation of images that are persisted in core data store and the undo works fine (of course, there may be a multitude of reasons why you opted for doc bundle).

    I wrestled with core data’s undo with regard to derived properties (ie: properties that were derived from the store data but not actually persisted). I implemented these as properties of my NSManagedObject subclass and wrought an acceptable level of undo performance that promptly failed on OS X 10.6. Turning my ivar backed subclass properties into modelled transient properties made the problem evaporate.

    So I suppose my thinking is when it comes to core data you really have to go with the flow and do things the core data way.

    The problem, of course, is that when you are learning this stuff it’s hard to know what way the flow goes!

    As for the file undo problem:
    I might have tried sticking with the in bundle undo support. Spotlight doesn’t index hidden folders so you could probably overcome that problem. As for the package/state consistency issue: if the bundle undo cache is cleared when the doc is opened/closed then I don’t see that as too problematic. If the doc bundle gets copied out from under you the undo cache gets cleared at the next load.

    Anyhow, all our design and coding decisions takes us down unexpected paths. The main thing is to make a decision, commit to it and, as you say, make it work, come hell or high water.

    Good posting.


Leave a Reply

This area is controlled in your WP admin under Apperance > Widgets. You need to add your desired widgets to one of the 9 widget areas (Footer1-9).