NSFetchedResultsController on OS X

Hi,


A UICollectionView-like NSCollectionView was on top of my wishlist for OS X 10.11. So I was extremely happy when it was announced at WWDC 2015.


It is great to work with a simple model as it was shown in the demo. However, because of the lack of an NSFetchedResultsController equivalent on OS X, it is much harder to use the datasource and delegate with Core Data. Do you know if there are any plans to port the handy NSFetchedResultsController to OS X 10.11?


The existing controllers on OS X (NSArrayController, NSTreeController, ...) are not adequate to effectively replace NSFetchedResultsController, either because they don't support sections or because they would be like using a sledgehammer to crack a nut.


So, without an NSFetchedResultsController equivalent, how can you efficiently use Core Data with the new NSCollectionView using its datasource and delegate (especially when you need to handle (ordered) sections)?


Thanks


I've filed a bug report for this issue (#22019377)

Replies

Romain,


Some time ago I faced a similar problem. I was making an OS X version of some existing iOS app and wanted to interface Core Data backend with an NSTableView/NSOutlineView. That iOS app used an NSFetchedResultsController with a UITableView and I was a really disappointed by the fact that NSFetchedResultsController is not available on OS X and I can't follow the same architecture. I looked at GitHub and CocoaPods but didn't find any serious FRC controller re-implementation for a desktop Cocoa. That's why I built my own.


https://github.com/konstantinpavlikhin/KSPFetchedResultsController


KSPFetchedResultsController follows NSFetchedResultsController API pretty closely, but it has a couple of important differences. You can find out all the details in a Readme.md file. To name a few — because my FRC version was made to serve as an NSTableView/NSOutlineView data source it operates on row indexes rather than NSIndexPaths. There are also two FRC classes, instead of one: KSPFetchedResultsController and a KSPSectionedFetchedResultsController. Neither NSTableView, not NSOutlineView support sections in a way that UITableView does. That's why I made separate classes. FRC is aimed to be an NSTableView data source, while SFRC is made for an NSOutlineView (you can imitate sections with NSOutlineView pretty easily).


KSPFetchedResultsController has tests and it is being used in a complex production-quality app, so it appears to be pretty reliable.


Hope it helps!