I have a to-one relationship in my data model with Core Data. I'm trying to set the value of the relationship but Core Data 开发者_JAVA技巧keeps thinking that it's nil. The "creatorUser" relationship is not optional, so when I go to save my managed object context, Core Data gives errors because it thinks the "creatorUser" is nil.
Any help would be greatly advised.
NSManagedObject *teamManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"DCTeam" inManagedObjectContext:_managedObjectContext];
// Creator Properties
NSManagedObject *creator = [self userForID:[ticketInfo objectForKey:@"userid"]];
if (!creator) {
creator = [NSEntityDescription insertNewObjectForEntityForName:@"DCUser" inManagedObjectContext:_managedObjectContext];
[creator setValue:[personInfo objectForKey:@"userid"] forKey:@"userid"];
[creator setValue:[personInfo objectForKey:@"creatorName"] forKey:@"name"];
}
[teamManagedObject setValue:creator forKey:@"creatorUser"];
The error I was getting was '1570'. That's the one that says that a non-optional relationship is nil. nall is correct, the relationship was supposed to be a to-many. This was an oversight by myself which is why Core Data didn't like pairing up the relationship.
Thanks to all that replied!
精彩评论