There is an entities where I am filling data from JSON, Say it is Photographer
and Photo
. Both have some data which I have filled using loop and managed ObjectContex
..
Like this,
NSMutableArray *ArrPhotographer= [[self.M3Arr objectForKey:@"LifeMag"]objectForKey:@"Photographer"];
for (int i = 0; i< ArrPhotographer.count; i++) {
Photographer * photographerObj = [NSEntityDescription insertNewObjectForEntityForName:@"PhotographerData"
inManagedObjectContext:[self managedObjectContext]];
NSMutableDictionary *tpDict = [cleanerListArr objectAtIndex:i];
photographerObj.cleanerName = [tpDict objectForKey:@"photographerName"];
}
Now I have done this for both Photographer and Photo Entity and as per this picture my Magazine entity is having data which are already existed in this table . And as shown I have made to one relation to both Photo and Photographer from Magazine .
Now Question is ,
If Photographer Name is already existed in the table , How can I connect it with Magazine Entity . I need the managed object Reference of that particular place .
(For Example , There are three photographer , Ron , Harry and Sunny now For Photo Cover1 I want name of Ron . then I need the Object Reference of Ron when I pre Populate it).
How to get this object Reference?
// **************** EDIT
I am getting the object is present ...but No how to fetch object and 2) how to give it to x and y stated above ?
I am using this code to saving the data in Magazine
Magazine *magObj = [NSEntityDescription insertNewObjectForEntityForName:@"Magazine"
inManagedObjectContext:[self managedObjectContext]];
magObj .issueID=[NSNumber numberWithInt:1];
magObj .photo= x;
magObj .photographer = y;
#### Edit 2
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Cleaner"];
[request setPredicate:[NSPredicate predicateWithFormat:@"cleanerName = %@", @"Robin"]];
[request setFetchLimit:1];
NSUInteger count = [[self managedObjectContext] countForFetchRequest:request error:nil];
if (count == NSNotFound){
NSLog(@"ERROR FOund");
}
// some error occurred
else if (count == 0){
NSLog(@"no matching object");
}
// no matching object
else{
NSLog(@"Found Match");
}