【发布时间】:2010-07-19 03:11:24
【问题描述】:
我试图弄清楚 KVC 机制在处理相互之间的反向关系的关系属性时是否提供任何帮助。我将使用人为的标准部门/员工示例。
@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;
有了这个(以及省略的 KVC 收集方法),KVC 为管理双向关系提供了什么样的帮助?我现在只是在概念阶段。我知道使用 Core Data 我可以设置显式反向关系,因此当我使用 [myDepartment insertObject:newEmployee inEmployeesAtIndex:lastIndex]; 时,newEmployee.department 会自动设置为 myDepartment,但是我可以仅使用 KVC 和运行时来实现这一点,还是我需要 Core Data ?
提前感谢您的帮助。
编辑有点不相关但也很重要,在我的代码中,我将 Employee 的属性设置为 Department 为 retain,但我想知道这是否会导致保留周期?
【问题讨论】: