Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetched Results Controller Support for SMStore.predicate Method #68

Open
Jerland2 opened this issue Dec 25, 2017 · 7 comments
Open

Fetched Results Controller Support for SMStore.predicate Method #68

Jerland2 opened this issue Dec 25, 2017 · 7 comments

Comments

@Jerland2
Copy link

Jerland2 commented Dec 25, 2017

Is there any chance someone could add support for Fetched Result Controllers and their delegates with the predicate method for NSPredicates? When using the predicate method my fetched result controllers fail to trigger its delegate methods. I have confirmed (at least I believe) that this issue is caused by the generated predicate due to the following SOF post:
https://stackoverflow.com/questions/17151160/nsfetchedresultscontroller-delegate-not-called-for-api-listener

@paulw11
Copy link
Owner

paulw11 commented Dec 27, 2017

Can you provide a small example project that demonstrates the issue?

@Jerland2
Copy link
Author

Jerland2 commented Dec 27, 2017

@paulw11
as requested here is a sample project displaying the bug/problem. also I will describe steps to reproduce below:
https://github.com/Jerland2/SeamPredicateTest

Steps to reproduce:

  1. Add 2 items using the "+" button on the initial page.
  2. Select an item
  3. Add Item on 2nd page -> NOTICE: It does not show up! This is the bug! The reason it does not show up is because the predicate is messing up the fetched results controller delegate. This predicate is the one generated from the SMStore .predicate method.
  4. In order to get items on 2nd page to show up: return to initial page and then navigate to the second page again.

@Jerland2
Copy link
Author

Jerland2 commented Jan 3, 2018

@paulw11 Wondering if there is any update/eta on this fix? I am really eager to add this feature to my app!!

@paulw11
Copy link
Owner

paulw11 commented Jan 4, 2018

I have been looking at this and I don't believe that it can be resolved.
You can use the object context change notification as a trigger to reload your data and refresh your tableview. Something like:

NotificationCenter.default.addObserver(forName: NSNotification.Name.NSManagedObjectContextObjectsDidChange, object: CoreDataController.shared.viewContext, queue: nil) { (notification) in
    self.loadData()
 }

Add a self.tableView.reloadData() to your loadData function

@Jerland2
Copy link
Author

Jerland2 commented Jan 8, 2018

@paulw11 this is sad news, perhaps you could reference why you think it isn’t possible for someone to implement in the future here?

Your suggestion would work for my reloading, however it still does not support the entire FRC delegate pattern, which is a HUGE issue as far as supporting Core Data and apps that use FRC’s to perform operations.

@paulw11
Copy link
Owner

paulw11 commented Jan 10, 2018

The problem seems to be with the way the FRC monitors changes and the disconnect between CloudKit references and the local MOC references. I have found a different predicate that you can use in your sample that works with the FRC delegate:

 fetchRequest.predicate = NSPredicate(format:"booksToPerson.name = %@", selectedPerson.name!)

@jwarrent
Copy link

This predicate pattern worked for me. In my case, I generate a unique UUID key for my Person entity so I can compare something much more likely to stay unique and keep on using FRC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants