I am working with core data app and my query is that I have a child and parent relationship with the parent relationship having inverse relationship with the child and in the parent entity with To many relationship checked,
So now my query is that I want to access the name of the parent lets say mother name by just giving the child name so i am using predicate for this here’s a view at my code
-(void)retrieveviaPredicate
{
NSFetchRequest *fetchReq = [[NSFetchRequest alloc]init];
[fetchReq setEntity:[NSEntityDescription entityForName:@"Child"
inManagedObjectContext:self.managedObjectContext]];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"Childname=='ravi'"];
[fetchReq setPredicate:pred];
NSArray *t = [self.managedObjectContext executeFetchRequest:fetchReq error:nil];
for(Child *p in t)
{
NSLog(@"%@",p.Childname);
for(Parent *p1 in p.childToParent)
{
NSLog(@"Mother name is %@",p1.MotherName);
}
}
}
In the above code I am getting a warning which says that
warning: NSManagedObject' may not respond to '-countByEnumeratingWithState:objects:count:
and when I run the app the app goes south, could you please help me out on this
Thanks and Regards
Radix
Check if
childToParentis a to-many relationship. I guess it’s not.the for loop would only work if it would be a to-many relationship:
EDIT:
what happens if you replace
with