Skip to content

Extensible drop-in replacement for NSFetchedResultsController.

License

Notifications You must be signed in to change notification settings

minima/MRFetchedResultsController

 
 

Repository files navigation

Version License Platform

MRFetchedResultsController

MRFetchedResultsController is a drop-in replacement for NSFetchedResultsController that works on Mac and iOS.

Its purpose is to provide an alternative that makes it possible to extend NSFetchedResultsController functionallity without having to deal with private APIs.

In apps ported to Mac OS X using Chameleon, MRFetchedResultsController addresses the lack of an implementation of NSFetchedResultsController for the platform by providing an alternative that can be used in both iOS and Mac versions of the apps.

Installation

CocoaPods

MRFetchedResultsController is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "MRFetchedResultsController"

Manually

Copy MRFetchedResultsController directory into your project.

Usage

After adding files under the MRFetchedResultsController folder to your project, you can use it as you would do with NSFetchedResultsController.

When extending MRFetchedResultsController, you can expose its private methods to categories and/or subclasses by importing MRFetchedResultsController+Internal.h.

When using the fetched results controller with UICollectionView you can handle content changes by implementing the method - (void)controller:(MRFetchedResultsController *)controller didChangeSections:(NSArray *)sectionChanges andObjects:(NSArray *)objectChanges in the delegate:

- (void)controller:(MRFetchedResultsController *)controller didChangeSections:(NSArray *)sectionChanges andObjects:(NSArray *)objectChanges
{
    [self.collectionView performBatchUpdates:^{
        for (id<MRFetchedResultsSectionChangeInfo> change in sectionChanges) {
            [change performUpdateInCollectionView:self.collectionView];
        }
        for (id<MRFetchedResultsObjectChangeInfo> change in objectChanges) {
            [change performUpdateInCollectionView:self.collectionView];
        }
    } completion:nil];
}

Extras

Besides the new delegate method that provides support for - [UICollectionView performBatchUpdates:completion:]; MRFetchedResultsController.h contains 3 extra properties -not present in NSFetchedResultsController.h- for fine-tuning the behaviour of the fetched results controller's change tracking:

// Changes in the context are not applied to the fetchedObjects array until applyFetchedObjectsChanges is set.
@property (nonatomic, assign) BOOL applyFetchedObjectsChanges;
// If set, changes in the context are not applied until the context is successfully saved.
@property (nonatomic, assign) BOOL changesAppliedOnSave;
// If set, it is used for notifying changes asynchronously.
@property (nonatomic, assign) dispatch_queue_t notifyChangesQueue;

License

MRFetchedResultsController is available under the MIT license. See the LICENSE file for more info.

Alternatives

About

Extensible drop-in replacement for NSFetchedResultsController.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 98.8%
  • Ruby 1.2%