Core Data to-many relationships and keyPathsForValuesAffectingValueForKey
Core Data to-many relationships and keyPathsForValuesAffectingValueForKey
- Subject: Core Data to-many relationships and keyPathsForValuesAffectingValueForKey
- From: email@hidden
- Date: Fri, 23 Nov 2007 11:48:37 +0100
Hi,
I have set up a Core Data model with two entities, Account and Operation.
Account has a to-many relationship With Operation named operations.
Operation has an attribute amount and Account has a property total (not in the
model) which is supposed to be the sum of the amount of all its operations.
I would like to trigger a KVO notification for the key total of an account
whenever the amount of one of its operations changes.
I know in 10.4 it wasn't ever possible as the method
setKeys:triggerChangeNotificationsForDependentKey: didn't work with keyPaths but
I suppose I should be able to do it in 10.5 with
keyPathsForValuesAffectingValueForKey.
I implemented method keyPathsForValuesAffectingValueForKey in Account.m as
follows :
- (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
NSMutableSet *keyPaths = [NSMutableSet setWithSet:[super
keyPathsForValuesAffectingValueForKey:key]];
if ([key isEqualToString:@"total"]) {
[keyPaths addObject:@"operations.amount"];
}
return keyPaths;
}
When trying to run my program, I get an error saying that _NSFaultingMutableSet
is not KVO compliant with key "amount".
So, how am I supposed to do this ?
Thanks,
Cyril Anger
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden