Re: NSArrayController -addObjects and undo - [SOLVED]
Re: NSArrayController -addObjects and undo - [SOLVED]
- Subject: Re: NSArrayController -addObjects and undo - [SOLVED]
- From: "email@hidden" <email@hidden>
- Date: Wed, 11 Nov 2009 23:21:21 +0000
On 10 Nov 2009, at 22:29, Quincey Morris wrote:
> On Nov 10, 2009, at 14:08, email@hidden wrote:
>
>> I accept all of this except that when observing NSArrayController -arrangedObjects it seems that NSKeyValueChangeSetting is all you ever get, regardless of the nature of the changes to the underlying content.
>
> If you're really getting a stream of NSKeyValueChangeSetting notifications for the same array property during undo, it would be worth submitting a bug report. The behavior indicates that whatever is responsible for KVO compliance (which might be Core Data itself, or the NSArrayController) isn't being careful about how it's applying the changes. It's still an implementation detail, but your expectation of *one* of those non-specific notifications (or several of the more fine-grained notifications) seem reasonable.
>
>> But from an NSUndoManager perspective it would seem like a rational expectation that is not met in practice.
>
> It's very unlikely that this is the undo manager's fault. It sounds more like a slight flaw in Core Data, or an "impedance mismatch" between Core Data and NSArrayController.
>
After a lot of experimentation I can define the issue better and a reasonable solution.
scenario:
1. CoreData NSManagedObject subclass.
2. KVO notifications raised for MO subclass properties.
3. N x MO subclass entries added to NSArrayController with -addObjects:. This invokes a single change to NSArrayController -arrangedObjects.
4. When undo is invoked NSArrayController -arrangedObjects is modified N times.
For me this N times modification of arrangedObjects was a problem.
The underlying issue is that NSArrayController -rearrangeObjects gets called multiple times.
The best solution seems to be to subclass NSArrayController and override -rearrangeObjects as a no-op if we are undoing.
/*
rearrange objects
*/
- (void)rearrangeObjects
{
// rearranging during undo causes performance issues
if (![[[self managedObjectContext] undoManager] isUndoing]) {
[super rearrangeObjects];
}
}
The mixture of bindings, KVO, CoreData and undo is a bit of a lethal brew.
And CoreData undo is definitely no free lunch.
It's easy to throw it all various technologies into the mix but it's another matter to get them to collaborate effectively.
>
> _______________________________________________
>
> 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
_______________________________________________
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