I'm trying to figure out if the KVC mechanisms provide any sort of help when dealing with relationship properties which are inverse relationships of each other. I'll use the contrived and standard Department/Employee example.
@interface Department : NSObject {
NSMutableArray *employees;
}
@property (retain) NSMutableArray *employees;
// KVC methods for mutating the employees array
@end
@interface Employee : NSObject {
Department *department;
}
@property (retain) Department *department;
With just this (and the omitted KVC collection methods) what kind of help does KVC provide for managing the relationship in both directions? I'm only at the conceptual stage right now. I know with Core Data I can set explicit inverse relationships and thus when I use [myDepartment insertObject:newEmployee inEmployeesAtIndex:lastIndex];
, then newEmployee.department
is automatically set to myDepartment
, but can I achieve this with solely KVC and the runtime, or do I need Core Data?
Thanks in advance for helping.
Edit Somewhat unrelated but also important, in my code I put Employee's property to Department as being retain
but I'm wondering if this will cause a retain cycle?