开发者

Core Data - Firing faults

If I have the entities Department and Employee, after fetching all the departments, I can see that the employees are still in fault开发者_StackOverflow. My goal is to get the set of employees related to a certain departament. From what I read in the documentation, I shouldn't need to fetch that because the fault is fired when it's necessary. I tried the following, but the set is still empty and NSLog shows that the employees are still fault:

Department *dep = (Department *)[self.fetchedDepController objectAtIndexPath:indexPath];
NSSet *employeesSet = [dep employee];
NSLog(@"Department: %@", dep);

What am I missing?


They will be faults until you access a property of the employees. For example:

NSSet *employeesSet = [dep employee];
for (Employee *employee in employeesSet) {
    float pay = 0.0;
    for (Day *day in employee.timecard) { // relationship fires fault
        float hours = (day.clockout - day.clockin) / 60.0 / 60.0;
        if (hours > 8.0) pay += employee.payrate * (8.0 + (hours - 8.0) * 1.5); // attribute would too
        else pay += employee.payrate * hours;
    employee.pay = pay; // so would setting an attribute

Because why do all the examples have to be for salaried employees?

That will fire the faults of all the employees.

But you normally don't need to worry about it, since any object that is a fault is supposed to cease being a fault any time you need it to. But yeah, I don't trust it either. If you have set up awakeFromFetch and didTurnInto fault, then you have the possibility of some dependence on when an object changes its nature. If you do things only like they intend and expect you to, then you have no problem, but the documentation isn't totally clear on what the limits of what's intended, allowed, and expected are.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜