1
votes

I'm using cocoa-binding to bind NSTableView to Core Data like the following

_arrayController = [[MyArrayController alloc] init];
[_arrayController setEntityName:@"User"];
[_arrayController setManagedObjectContext:self.managedObjectContext];
[_arrayController setUsesLazyFetching:NO];

[self.tableView bind:NSContentBinding toObject:self.arrayController withKeyPath:@"arrangedObjects" options:nil];

[_arrayController fetch:nil];

and everything seems to work well.

But one thing I don't understand is the effect of automaticallyPreparesContent and automaticallyRearrangesObjects properties of NSArrayController. According to the documentation, both are NO by default and I didn't change them either. Doc says

If flag is YES and a managed object context is set, the initial content is fetched from the managed object context using the current fetch predicate. The controller also registers as an observer of its managed object context. It then tracks insertions and deletions of its entity using the context's notifications, and updates its content array as appropriate.

and I think it means, if the flag is NO, content array isn't updated with newly inserted objects to managed object context. But it is updated when I insert a new managed object to the managed object context. What do I misunderstand?

And, about automaticallyRearrangesObjects Doc says

Sets whether or not the receiver automatically rearranges its content to correspond to the current sort descriptors and filter predicates.

which means, I think, if the flag is NO, content isn't rearranged even if array controller's sort descriptors or filter predicate are changed. But it is! When I change filter predicate or sort descriptors, rows on table view, which is bound to the array controller, are rearranged.

I'm quite confused of what I don't know or do misunderstand about NSArrayController's behaviors.

1

1 Answers

3
votes

‘automaticallyPreparesContent’ determines whether an initial fetch to populate the arrayController is done on the CoreData database automatically, or if you have to do it yourself.

You might turn it off if you want to do a special fetch or do some extra set-up in your code before the initial fetch.

‘automaticallyRearrangesObjects’ determines whether the arrayController will re-sort when you change one of the values in your objects, not whether it’ll re-sort when you change the sorts or filters. Like, if you’re sorting on “title” and you change an object’s title, will you have to manually tell the arrayController to update itself or will it happen automatically.

You might turn this latter one off if you have thousands of rows, because it’s actually quite slow to set up KVO on tons of items.