Questions tagged [nsfetchedresultscontroller]

An Apple fetched results controller is used to efficiently manage the results returned from a Core Data fetch request to provide data usually for a UITableView or UICollectionView object. It is available in iOS 3.0 and later.

An Apple controller used to efficiently manage the results returned from a Core Data () fetch request to provide data for a UITableView or UICollectionView object.

From Apple Official NSFetchedResultsController Document, fetched results controllers provide the following features:

  • Optionally monitor changes to objects in the associated managed object context, and report changes in the results set to its delegate (see: The Controller’s Delegate).

  • Optionally cache the results of its computation so that if the same data is subsequently re-displayed, the work does not have to be repeated (see: The Cache).

Example:

NSFetchedResultsController *controller = [[NSFetchedResultsController alloc]
    initWithFetchRequest:fetchRequest
    managedObjectContext:context
    sectionNameKeyPath:nil
    cacheName:@"<#Cache name#>"];

[fetchRequest release];

Questions in Stack overflow related coredata

  1. Good tutorials or good for using Core.Data in IOS 7

  2. JSON and Core Data on the iPhone

  3. Why use NSFetchedResultsController?

2287 questions
11
votes
2 answers

A-Z Index from NSFetchedResultsController with individual section headers within each letter?

I have an NSFetchedResultsController which fetches data from a Core Data structure, a list of albums. It's currently sorted by the artist, so all the A's, B's, etc. I want to add an index so the user can quickly jump to each letter, and I'm using…
Luke
  • 9,512
  • 15
  • 82
  • 146
11
votes
4 answers

NSFetchedResultsController: Fetch in a background thread

I have a more or less basic UITableViewController with a NSFetchedResultsController. The UITableViewController is pushed onto the navigationController's stack. But the push animation isn't smooth because the fetch of NSFetchedResultsController is…
11
votes
2 answers

UICollectionView decoration in empty collection view

I've implemented an UICollectionView with a custom layout. It adds a decoration view to the layout. I use the following code to add layout attributes of the decoration view: -(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { NSArray…
10
votes
3 answers

AQGridView backed by a NSFetchedResultsController

I'm trying to implement a AQGridView that uses a fetched results controller as its datasource. I'm not particular sure how to handle the NSFetchedResultsController delegate methods using the grid view; namely the content changing ones. I understand…
10
votes
4 answers

Crash on UITableView endUpdates when moving last row in section

I have an UITableViewController which is backed by an NSFetchedResultsController. My NSFetchedResultsController put results into two sections based on a boolean. In a background thread, the datasource is altered such that rows are added or…
Alex Taylor
  • 1,823
  • 1
  • 13
  • 26
10
votes
1 answer

sectionNameKeyPath with NSFetchedResultsController not working

I have an entity Order with property paid, which is a boolean. I want to display all orders in a UITableView, but I want to group them in two sections: 'Not Paid' and 'Paid'. So I thought I'd just give "paid" as sectionNameKeyPath, like…
Rits
  • 5,105
  • 4
  • 42
  • 53
10
votes
3 answers

Unable to infer complex closure return type; add explicit type to disambiguate

Does anybody know how I can solve this error that I'm getting? The error is received on the first line in the following chunk of code: let fetchedResultsController: NSFetchedResultsController = { let fetchRequest =…
random1234
  • 777
  • 3
  • 17
  • 41
10
votes
1 answer

How to handle NSFetchedResultsController fetch errors?

This is from the Apple sample code: if (![fetchedResultsController_ performFetch:&error]) { /* Replace this implementation with code to handle the error appropriately. ... If it is not possible to recover from the error, ... …
fabian789
  • 8,348
  • 4
  • 45
  • 91
10
votes
4 answers

NSFetchedResultsController section ordering using display order

I currently have an option that allows a user to change the display order of a category in my iPhone app. I want to section the table view using a NSFetchedResultsController so that the section titles are the "category.name" ordered by…
avenged
  • 567
  • 1
  • 8
  • 19
10
votes
1 answer

NSFetchedResultsController ERROR: The fetched object at index 248 has an out of order section name

trying the solution here: https://stackoverflow.com/questions/1741093?tab=newest#tab-top I'm using a transient property and the category solution and it seems to be working right up until the index char starts to wrap around to the A's again, not…
Cricketgeek
  • 381
  • 3
  • 7
10
votes
2 answers

Strange parent / child NSManagedObjectContext phenomenon

I have created two context like this: // create writer MOC _privateWriterContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; [_privateWriterContext…
János
  • 32,867
  • 38
  • 193
  • 353
10
votes
3 answers

How can I get number of objects in section, NSFetchedResultsController Swift

How can I get number of objects in section of an NSFetchedResultcController in Swift? if let s = self.fetchedResultsController?.sections as? NSFetchedResultsSectionInfo { } is giving me Cannot downcast from '[AnyObject]' to non-@objc…
SirRupertIII
  • 12,324
  • 20
  • 72
  • 121
10
votes
1 answer

iOS UITableView sections with fetchedResultsController confusion

I have an entity being displayed in a table view in just one section. The entity has two attributes, workoutName and trainingLevel. Both are of string type. Training level consists of the 3 types: 1, 2, 3. (trainingLevel = (Integer 16 or String…
user2512523
  • 1,229
  • 2
  • 15
  • 25
10
votes
1 answer

Core Data Sort By Multiple Sort Descriptors With CaseInsensitiveCompare

I have a Word : NSManagedObject subclass that I'm trying to group by the first letter of the word. In each section I'm then trying to sort by the length property while maintain the alphanumeric sort when words have the same length. So it would…
aahrens
  • 5,522
  • 7
  • 39
  • 63
10
votes
4 answers

Is NSFetchedResultsControllerDelegate 'ChangeUpdate' behavior broken?

The docs for NSFetchedResultsControllerDelegate provide the following sample code - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath …
Luther Baker
  • 7,236
  • 13
  • 46
  • 64