Error: Unrecognised selector sent to instance

I'm getting this error because it seems the database forgets objects relations. I always use the same context (with different instances on each function), so I think I can't do anything with mutableSetValue. Also, I've tried to set retainsRegisteredObjects, but it doesn't seem to improve anything. An option I was thinking about is always using the same context and send it from one function to the next one, but it doesn't feel like that's an optimal solution. And I'm not sure if relations would stay after I closed the app, which is something I need. Any ideas of how to solve this issue?

Could you show the code, that will be more informative that a description of the code. And tell where exactly you get the issue.

It happens in different parts of the code. For example, Topic has a one to many relation with group let fetch = NSFetchRequest<Group>(entityName: "Group"); fetch.predicate = NSPredicate(format: "topic = %@", topic); let groups = (try? context.fetch(fetchRequest)) ?? []; I get: NSInvalidArgumentException, reason: [project_name.Topic longlongValue]: unrecognized selector sent to instance. I made sure the relation is correctly created. But it seems that when I change the context instance, the relation disappears. The context is an object that I create from I class where I have the container. I create the same reference for every function.

Ensure there is not another fetch request named fetchRequest because you're declaring a let fetch = ... but passing a fetchRequest to the context.fetch(...) instead.

Error: Unrecognised selector sent to instance
 
 
Q