On 13 Jan 2014, at 16:29, Kyle Sluder <k...@ksluder.com> wrote: > On Mon, Jan 13, 2014, at 07:21 AM, Markus Spoettl wrote: >> Hi, >> >> I have an app that uses UIDocument and NSUndoManager. That way the >> system >> picks up changes to the data and knows when to auto-save. >> >> Some parts of the model are not using the undo manager (mostly settings >> where >> undo makes no sense or isn't wanted). Still that data is stored alongside >> the >> main data. >> >> What I want is that iOS saves whenever the app is backgrounded. >> >> So the questions is: Can I safely call -updateChangeCount: when my app is >> being >> sent to the background alongside the automatic NSUndoManager change >> handling? >> >> It seems to work quite nicely (when called from the app delegate's >> -applicationWillResignActive:), but I'm not sure if that's just an >> illusion and >> there's trouble waiting down the road. >> >> Any thoughts? > > This does not strike me as a good idea. -updateChangeCount: is a > counter; adding a place that increments the counter without having a > corresponding decrement sounds like an invitation for state corruption, > particularly in the presence of framework code that treats the counter > as normal.
You’ve got a good point here. Consider the steps of: 1. Make change, with corresponding undo registration 2. Update document change count 3. Undo, twice The change counter is now back at where it was at the start, probably leading the document to believe it has no unsaved changes, when in reality, the undo manager has actually wound back to some earlier state before step 1. So that does suggest mixing undo manager and manual change counting isn’t a good idea. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com