Fatal error fetching Entity with NSSet using FetchedResultController

40 views Asked by At

I have 2 Entities in my Project:

Product: NSObject {
    @NSManaged public var title: String?
}

ShoppingCart: NSObject {
    @NSManaged public var products: NSSet?
}

I want to subscribe to ShoppingCart updates on one of my ViewControllers and update the tableView inside.

I found the solution that I can do it by using NSFetchedResultsControllerDelegate, but while configuring it I'm getting fatal error "to-many key not allowed here"

if fetchedResultsController == nil {
            let request = NSFetchRequest<ShoppingCart>(entityName: "ShoppingCart")
            let sort = NSSortDescriptor(key: "products", ascending: false)
            request.sortDescriptors = [sort]
            
            fetchedResultsController = NSFetchedResultsController(fetchRequest: request, managedObjectContext: CoreDataService.managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
            fetchedResultsController.delegate = self
        }
        
        do {
            try fetchedResultsController.performFetch()
            tableView.reloadData()
        } catch {
            print("failed fetch")
}

I'm stuck on this task like 3 days or so, give me a hand please

0

There are 0 answers