Reputation: 91
I have two entities, one called projects and one called tasks, and projects can have many tasks to them. I have a fetch request that should fetch all the tasks associated with a project, but I am getting this error when tapping on a project to move to the view with the project's tasks on it:
Thread 1: Exception: "-[__NSConcreteUUID longLongValue]: unrecognized selector sent to instance 0x600002969b20"
Here are my two classes:
extension ProjectItem {
@NSManaged public var projectId: UUID
@NSManaged public var projectTitle: String
@NSManaged public var task: NSSet
}
extension TaskItem {
@NSManaged public var id: UUID
@NSManaged public var isComplete: Bool
@NSManaged public var title: String
@NSManaged public var project: ProjectItem?
}
And here is my view and fetch request:
struct ProjectDetail: View {
@Environment(\.managedObjectContext) var managedObjectContext
@ObservedObject var projectItem: ProjectItem
private var tasksInProject: FetchRequest<TaskItem>
private var taskItems: FetchedResults<TaskItem> { tasksInProject.wrappedValue }
init(_ project:ProjectItem) {
self.projectItem = project
self.tasksInProject = FetchRequest(
entity: TaskItem.entity(),
sortDescriptors: [NSSortDescriptor(keyPath: \TaskItem.createdDate, ascending: false)],
predicate: NSPredicate(format: "project == %@", project.projectId as CVarArg))
}
...
var body: some View {
ForEach(taskItems, id:\.id) { taskItem in
Text("\(taskItem.title)")
}
}
Please help! I have been pulling my hair out over this for over a week now.
Upvotes: 1
Views: 79
Reputation: 258443
The TaskItem.project
is type of ProjectItem?
not UUID, so try
self.tasksInProject = FetchRequest(
entity: TaskItem.entity(),
sortDescriptors: [NSSortDescriptor(keyPath: \TaskItem.createdDate, ascending: false)],
predicate: NSPredicate(format: "project.projectId == %@", project.projectId as CVarArg))
Upvotes: 1