Re: NSArrayController - error inserting object at arranged object index N
Re: NSArrayController - error inserting object at arranged object index N
- Subject: Re: NSArrayController - error inserting object at arranged object index N
- From: Jonathan Mitchell <email@hidden>
- Date: Thu, 23 Jun 2016 21:39:08 +0100
> On 23 Jun 2016, at 17:51, Quincey Morris <email@hidden> wrote:
>
>
>> My workaround was to set controller.clearsFilterPredicateOnInsertion == YES and reset the filterPredicate following -addObject:
>>
>> It might be possible to subclass NSArrayController …
>
> There’s no need to work around at all. The correct, straightforward solution is to update the content array (i.e. the unfiltered objects being managed via the array controller) directly in a KVO compliant manner, using ‘mutableArrayValueForKey:’.
>
Do you mean something like this?
NSMutableArray *proxy = [NSArrayController mutableArrayValueForKey:@"content"];
[proxy addObject:object];
[proxy filterUsingPredicate:self.filterPredicate];
This does work but is very slow even with a small collection (the subclass returned is an instance of NSKeyValueSlowMutableArray).
Perhaps NSArrayController does not override all the required KVC methods for the content key?
[self.submissionsArrayController addObject:object];
self.submissionsArrayController.filterPredicate = self.filterPredicate;
The above amounts to the same thing and seems much more performant.
I suppose I could make my NSViewController class KVC compliant for the content array but that seems overkill in this case.
Thanks
J
_______________________________________________
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