2
votes

I have a fetched results controller which isn't calling its' delegate when it has a predicate. The predicate is to only include Conversation objects which have events:

    let predicate = NSPredicate(format: "events.@count > 0")

    let fetchRequest = Conversation.MR_requestAllSortedBy(
        "mostRecentMessage.eventDate",
        ascending: false,
        withPredicate: predicate)
    self.fetchedResultsController = NSFetchedResultsController(
        fetchRequest: fetchRequest,
        managedObjectContext: MagicalRecordStack.defaultStack()!.context,
        sectionNameKeyPath: nil,
        cacheName: nil)
    self.fetchedResultsController.delegate = self

    self.fetchedResultsController.MR_performFetch()

This works for an initial fetch, but upon data being added, it doesn't call the delegate. Upon removing the predicate, it does call the delegate.

Is there another way I should be doing this?

1
Does the added data satisfy the requirement events.@count > 0?FreeNickname
Yes. Upon re-launching the app (thus calling performFetch), it updates showing the added data.Andrew

1 Answers

0
votes

The fetch predicate can only check against Core Data attributes because the objects themselves remain as faults. The fetch predicate doesn't get all of the objects of the requested entity and then filter them, it just fetches the ones that pass the filter predicate.

As a work around you could fetch the Event entity. Then use the section key to group by Conversation.