Setting a value in one entity programmatically from another entity in Core Data
In Core Data, 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 ma开发者_如何学编程ny 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?
You are using a key path. You should use setValue:forKeyPath:
instead.
精彩评论