DJFetchedResultsController 1.1.0

DJFetchedResultsController 1.1.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Oct 2015

Maintained by David Jennes.



  • By
  • David Jennes

DJFetchedResultsController

Version License Platform

NSFetchedResultsController sub-class that allows the user to prepend and/or append some static data using NSArray's. The user can also specify if these items should be in a separate section or 'inline' with the fetched items from the FRC.

Demo

To try the example project, just run the following command:

pod try DJFetchedResultsController

Requirements

Requires iOS 6 or higher.

Installation

From CocoaPods

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

pod "DJFetchedResultsController"

Manually

Important note if your project doesn't use ARC: you must add the -fobjc-arc compiler flag to all 'DJFetchedResultsController' files in Target Settings > Build Phases > Compile Sources.

  • Drag the DJFetchedResultsController/DJFetchedResultsController folder into your project.

Usage

Importing headers

Then simply add the following import to your prefix header, or any file where you wish to use the custom FRC.

#import <DJFetchedResultsController/DJFetchedResultsController.h>

Creating the FRC

You can simply create a new FRC using any of the provided initializers:

  • Creating a new FRC on the fly:

    DJFetchedResultsController *frc = [[DJFetchedResultsController alloc] initWithFetchRequest: myFetchRequest managedObjectContext: myContext sectionNameKeyPath: nil cacheName: nil];
    frc.prependItems = @[@"one", @"two", @3];
    frc.appendItems = @[@"four", @"five", @"last"];
    
  • Passing along an existing FRC:

    DJFetchedResultsController *frc = [[DJFetchedResultsController alloc] initWithFetchedResultsController: myFetchedResultsController];
    frc.prependItems = @[@"one", @"two", @3];
    frc.appendItems = @[@"four", @"five", @"last"];
    

The newly created FRC can be used as you would any other FRC in UITableViewController, UICollectionViewController, etc...

Modifying the static data

At any time, you can change the prepend (or append) static data by simply assigning a new array to the property, eg.:

frc.prepend = @[@"new", @"content", @"here"];

Internally, will change, did change and other events will be generated as expected, just as if you modified the items from Core Data.

Important:

Never modify the existing arrays, otherwise the necessary FRC events will not be generated. So never do this:

[frc.prepend addObject: @"new item"];

Instead, do this:

NSMutableArray *items = frc.prepend.mutableCopy;
[items addObject: @"new item"];
frc.prepend = items;

Credits

DJFetchedResultsController is brought to you by David Jennes.

License

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