Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

hectr/MRRealmResultsController

Repository files navigation

Version License Platform

MRRealmResultsController

This is untested and undocumented code not suitable for production use.

MRRealmResultsController is an alternative to NSFetchedResultsController for use with realm-cocoa.

I've made it because I wanted to check how well could Realm perform when used as a replacement to Core Data in an existing application with as few changes as possible made to the application code.

The MRRealmResultsControllerExample project is essentially the TableView from RealmExamples with some modifications to demonstrate the use of MRRealmResultsController.


The key differences between NSFetchedResultsController and MRRealmResultsController interfaces reside in the following methods:

// NSFetchedResultsController
- (id)initWithFetchRequest:(NSFetchRequest *)fetchRequest
      managedObjectContext: (NSManagedObjectContext *)context 
        sectionNameKeyPath:(NSString *)sectionNameKeyPath 
                 cacheName:(NSString *)name;
                 
// MRRealmResultsController
  - (id)initWithClass:(Class)objectClass
            predicate:(NSPredicate *)predicate
                realm:(RLMRealm *)realmOrNil
       sortDescriptor:(NSSortDescriptor *)sortDescriptor
sectionSortDescriptor:(NSSortDescriptor *)sectionSortDescriptorOrNil
       andNameKeyPath:(NSString *)sectionNameKeyPath;

// NSFetchedResultsControllerDelegate
- (void)controller:(NSFetchedResultsController *)controller 
   didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath 
     forChangeType:(NSFetchedResultsChangeType)type 
      newIndexPath:(NSIndexPath *)newIndexPath;
- (void)controller:(NSFetchedResultsController *)controller 
  didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo 
           atIndex:(NSUInteger)sectionIndex 
     forChangeType:(NSFetchedResultsChangeType)type;

// MRRealmResultsControllerDelegate
- (void)controller:(MRRealmResultsController *)controller
  didChangeSection:(id <MRRealmSectionInfo>)sectionInfo
           atIndex:(NSUInteger)sectionIndex
     forChangeType:(MRRealmResultsChangeType)type;

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

CocoaPods

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

pod "MRRealmResultsController"

Manually

Perform the following steps:

License

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

Alternatives

About

MRRealmResultsController is an alternative to NSFetchedResultsController for use with realm-cocoa.

Resources

License

Stars

Watchers

Forks

Packages

No packages published