Joining iPhone CoreData

this is my main data model:

enter image description here

I am trying to get all LanguageEntries from a database for this category. categoryName and languageset.languageSetName, for example.

NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"LanguageEntry" inManagedObjectContext:del.managedObjectContext];
    [fetchRequest setEntity:entity];

NSString* predicateString = [NSString stringWithFormat:@"Category.categoryName = %@ AND LanguageSet.languageSetName = %@", 
                        @"Food", @"English####Spanish"];

fetchRequest.predicate = [NSPredicate predicateWithFormat:predicateString];

NSError *error = nil;
NSArray* objects = [del.managedObjectContext executeFetchRequest:fetchRequest error:&error];

This always returns 0 objects. If I set the predicate string according to one relationship (for example, Category.categoryName = Food or languageSet.languageSetName = English #### Spanish), it will return the data.

It puzzles if anyone can shed some light?

-> Ken

+3
source share
2 answers

Core Data SQL. Core Data , "". . , . .

"==" :

@"Category.categoryName == %@ AND LanguageSet.languageSetName == %@"

, .

. , . "LanguageEntity", . , . , .

+9

, predicateWithFormat. :

fetchRequest.predicate = [NSPredicate predicateWithFormat:@"Category.categoryName = %@ AND LanguageSet.languageSetName = %@", 
                                                          @"Food", 
                                                          @"English####Spanish"];

, , , , . NSString, .

+1

Source: https://habr.com/ru/post/1737233/


All Articles