I have an entity with a relationship with itself. I have declared a first to-many relationship named children. And a one to one named parent.
children - Property - parent
parent - Property - children
Then I generated the class with xcode. In particular it fails whenever I try to add new Children objects. This is the relevant piece of code
- (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:@"c开发者_开发知识库hildren" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[changedObjects release];
}
This is how I create the entity
NSEntityDescription *entityProperty = [[self.managedObjectModel entitiesByName] objectForKey:@"Property"];
WZMDXProperty *p = [[WZMDXProperty alloc] initWithEntity:entityProperty insertIntoManagedObjectContext:self.managedObjectContext];
It fails with a message like NSString addObject: unrecognized selector which is the typical message I get with too soon released object. It seems that primitive value for key give other objects rather than the NSSet. I have tried with the inspector, but I wasn't able to spot the error.
it's a bit unlikely, but, have you ever tried to replace @"children" with @"Children" ? You're using "Children" all over here, except in the code segment
精彩评论