I have three core data entities which I am importing into, they are:
• sizes (Name, Clothes (one to many with "Clothes" entity))
• Clothes (Name, Price, etc... +2 relationships)
• shop (Name, Clothes (one to many to "Clothes" entity))
I have imported shops, into shop and sizes into the sizes entity.
Now I am importing the clothes. At the start I do a fetch request on the sizes and shops and store them to an array.
I am looping through all the clothes and populating the dictionary then I predicate on the array's for the for the shop name and size to get the managed object for each and then try and store that against the relationship and it does not work?
If though I do [arrShops objectAtIndex: x] and store that it works?
What is wrong with predicat'ing I cant get the correct managed object any other way can I?
Or is there another way of setting up this relationship?
Thanks James
EDIT
I have a method like this to get/predicate the shop:
- (void) getShops {
NSManagedObjectContext *moc = [(ImportingAppDelegate *) [[UIApplication sharedApplication] delegate] managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Shop" inManagedObjectContext:moc]];
NSError *error;
arr_Manufacturers = [moc executeFetchRequest:fetchRequest error:&error];
NSLog(@"get: %@", [arr_Shops count]);
[fetchRequest release];
}
- (id) getShop:(NSString *)name {
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"Shop = %@", name];
return [arr_Shops filteredArrayUsingPredicate:predicate];
}
Then when trying to store i do the following:
moc_Clothes.Shop = [self getShop:@"Shop Name Variable"];