Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OS X replacement for NSFetchedResultsController

So I'm used to iOS development so I'm pretty happy with NSFetchedResultsController. However, this is not present in the Mac OS X environment. I know that I can use NSArrayController as a replacement. I might be using this class terribly wrong but it worked until now. I initialize the NSArrayController as follows:

NSArrayController* newConversationsController = [NSArrayController new];
newConversationsController.managedObjectContext = context;
newConversationsController.entityName = entityName;
newConversationsController.sortDescriptors = sortDescriptors;
newConversationsController.automaticallyRearrangesObjects = YES;

NSError* error = nil;
[newConversationsController fetchWithRequest:nil merge:NO error:&error];
NSCAssert(!error, error.description);

Then I listen to changes of the NSManagedObjectContext and fetch and reload the NSTableView as follows:

        [self.conversationsController fetchWithRequest:nil merge:YES error:&error];
    NSAssert(!error, error.description);

    [self.tableView reloadData];

As I previously mentioned, I might be using this totally wrong but I don't like to use bindings. Now to the actual issue: Another class of the application might delete an NSManagedObject held by the NSArrayController. The NSArrayController instantly releases this deleted object and makes it impossible for me to figure out which object that was. The final goal is to know what object at what index has been deleted so I can animate the rows of the NSTableView.

I hope it's clear what I'm aiming at. Thanks for any help

like image 960
lbrndnr Avatar asked Jan 19 '14 10:01

lbrndnr


1 Answers

there are no sections in a NSTableView so there is no 1:1 replacement

BUT NSArrayController is a close match! It also fetches and sorts CoreData entities.

For the UI you'd use bindings then (but of course you don't have to)


e.g. see:

http://cocoadevcentral.com/articles/000080.php

like image 119
Daij-Djan Avatar answered Nov 12 '22 02:11

Daij-Djan