【发布时间】:2011-08-02 15:28:13
【问题描述】:
我有一个与自身有关系的实体。 我已经声明了一个名为 children 的第一对多关系。还有一对一命名的父母。
children - Property - parent
parent - Property - children
然后我用 xcode 生成了这个类。特别是当我尝试添加新的 Children 对象时它会失败。这是相关的代码
- (void)addChildrenObject:(WZMDXProperty *)value {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"children" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"children"] addObject:value]; // <<--FAILS HERE !!!!
[self didChangeValueForKey:@"children" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[changedObjects release];
}
这就是我创建实体的方式
NSEntityDescription *entityProperty = [[self.managedObjectModel entitiesByName] objectForKey:@"Property"];
WZMDXProperty *p = [[WZMDXProperty alloc] initWithEntity:entityProperty insertIntoManagedObjectContext:self.managedObjectContext];
它失败并显示类似 NSString addObject: unrecognized selector 的消息,这是我收到的过早释放对象的典型消息。 似乎键的原始值提供了其他对象而不是 NSSet。 我已经尝试过检查员,但我无法发现错误。
【问题讨论】:
标签: objective-c core-data entity-relationship