NSFetchedResultsController always includes temporary objects

I have NSFetchedResultsControllerone that I installed as follows:

        let fetchRequest = NSFetchRequest(entityName: "Order")
        fetchRequest.includesPendingChanges = false
        fetchRequest.sortDescriptors = [
            NSSortDescriptor(key: "status", ascending: false),
            NSSortDescriptor(key: "date", ascending: false)]

        self.fetchedResultsController = NSFetchedResultsController(
            fetchRequest: fetchRequest,
            managedObjectContext: DataStoreManager.sharedInstance.mainContext,
            sectionNameKeyPath: "section",
            cacheName: nil)

        do {
            try self.fetchedResultsController.performFetch()

        } catch let error as NSError {
            print(error)
        }

The problem is even when set includesPendingChangesto false, it still causes calls controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?)every time I create a new object in context (without saving).

Is there anything else I should look for to avoid this situation?

+4
source share
1 answer

The recommended way is to use a child context. The parent must be the primary object controlled by the stream of objects used in the selected result controller.

, "" , .. . ( .)

, . .

+5

Source: https://habr.com/ru/post/1625384/


All Articles