TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Oct 2015 |
Maintained by David Jennes.
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.
To try the example project, just run the following command:
pod try DJFetchedResultsController
Requires iOS 6 or higher.
DJFetchedResultsController is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "DJFetchedResultsController"
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.
DJFetchedResultsController/DJFetchedResultsController
folder into your project.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>
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...
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.
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;
DJFetchedResultsController is brought to you by David Jennes.
DJFetchedResultsController is available under the MIT license. See the LICENSE file for more info.