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
126
votes
9 answers

NSPredicate: filtering objects by day of NSDate property

I have a Core Data model with an NSDate property. I want to filter the database by day. I assume the solution will involve an NSPredicate, but I'm not sure how to put it all together. I know how to compare the day of two NSDates using…
101
votes
1 answer

Implementing Fast and Efficient Core Data Import on iOS 5

Question: How do I get my child context to see changes persisted on the parent context so that they trigger my NSFetchedResultsController to update the UI? Here's the setup: You've got an app that downloads and adds lots of XML data (about 2 million…
60
votes
6 answers

Is there a way to instantiate a NSManagedObject without inserting it?

I have a user interface to insert a Transaction. once the user clicks on a plus he gets the screen and i want to instantiate my Core Data NSManagedObject entity let the user work on it. Then when the user clicks on the Save button i will call the…
47
votes
6 answers

iOS 9 - "attempt to delete and reload the same index path"

This is an error: CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. attempt to delete and reload the same index path ( {length = 2,…
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
47
votes
12 answers

NSFetchedResultsController crashing on performFetch: when using a cache

I make use of NSFetchedResultsController to display a bunch of objects, which are sectioned using dates. On a fresh install, it all works perfectly and the objects are displayed in the table view. However, it seems that when the app is relaunched I…
Oliver
  • 1,279
  • 5
  • 14
  • 20
47
votes
6 answers

Illegal attempt to establish a relationship 'xyz' between objects in different contexts

I am using Apple's CoreDataBooks sample application as a basis for pulling data into a secondary managed object context in the background, and then merging that data into the primary managed object context. The data I am pulling in is a Book entity…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
41
votes
1 answer

Search Core Data for all objects with an empty "to-many" relationship

In an almost identical situation to Core Data - Fetch all objects NOT in a relationship, only I'm looking for all records of one type that are not in any to-many relationship with another type. So let's say I've got a set of patients, and a set of…
bryanjclark
  • 6,247
  • 2
  • 35
  • 68
41
votes
4 answers

Core Data NSFetchedResultsController - Total number of records returned

I'm using an NSFetchedResultsController in an iPhone app, and am wondering if there is some easy way of getting the total number of rows returned in all sections. Instead of getting the [[fetchedResultsController sections] count] and then looping…
Neal L
  • 4,329
  • 8
  • 34
  • 39
41
votes
7 answers

Core Data - How to fetch an entity with max value property

I have a entity Person with a property personId (personId is unique) How can I fetch the Person with the max personId? (I want to fetch the person itself not the value of the property)
Eyal
  • 10,777
  • 18
  • 78
  • 130
40
votes
4 answers

NSFetchedResultsController: changing predicate not working?

I'm writing an app with two tables on one screen. The left table is a list of folders and the right table shows a list of files. When tapped on a row on the left, the right table will display the files belonging to that folder. I'm using Core Data…
35
votes
3 answers

(NSFetchedResultsController): couldn't read cache file to update store info timestamps

I upgraded my project to Xcode 8. Now, I'm getting this error log with Xcode 8 and iOS 10 combination. Setting the cacheName to nil in the below code seems fix it. NSFetchedResultsController *frc = [[NSFetchedResultsController alloc]…
iCanCode
  • 1,001
  • 1
  • 13
  • 24
34
votes
4 answers

Core Data viewContext not receiving updates from newBackgroundContext() with NSFetchedResultsController

In my application, I have a NSFetchedResultsController to load Core Data objects in a UITableView. The fetch request associated with this FRC uses the new viewContext property available for the NSPersistentContainer (iOS10). When I select a cell, I…
33
votes
4 answers

NSFetchedResultsController with relationship not updating

Let's say I have two entities, Employee and Department. A department has a to-many relationship with an employee, many employees can be in each department but each employee only belongs to one department. I want to display all of the employees in a…
Adam S.
  • 1,251
  • 1
  • 12
  • 16
32
votes
7 answers

Core Data nested managed object contexts and frequent deadlocks / freezes

I have a problem that is almost identical to the problem described by this person here, but it hasn't get answered: http://www.cocoabuilder.com/archive/cocoa/312683-core-data-nested-managed-object-contexts-and-frequent-deadlocks.html#312683 Here is…
30
votes
4 answers

Can you do custom animations for UITableView Cell Inserts?

I've got a UITableView that is being populated by an NSFetchedResultsController. On the initial load of the table I would like the Cells to be animated in but I would like to do a little bit more custom animation than [tableView…
1
2 3
99 100