Question

I'm fairly new to Core Data, have looked through many tutorials and forums and haven't found the elegant solution to my problem:

I've got three entities in my model: Worker, Task, and SubTask. Each has a to-many relationship to the entity below it and a to-one inverse. Worker has many Tasks, each Task has many SubTasks, each SubTask has one parentTask, and each Task has one Worker. SubTask has a startTime attribute that gets set to the current time in the newObject method and a button that triggers endSubTask method in my SubTaskArrayController class. endSubTask calculates the time between startTime and now and sets that value for the SubTask attribute timeWorked. So far so good. The problem:

What is the best way to get the selected Task's totalTimeWorked attribute to update itself?

When I try something like

[currentSubTask setValue:newTotalTime forKey:@"parentTask.totalTimeWorked"];

I get:

[ setValue:forUndefinedKey:]: the entity SubTask is not key value coding-compliant for the key parentTask.totalTimeWorked.

How do I access the attributes of the parentTask of the currently selected SubTask?

Was it helpful?

Solution

You are using a key path. You should use setValue:forKeyPath: instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top