私はモデルを持っています:
場所<--->>カテゴリ
次のクエリを実行する場合:
NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"Category"];
if(![searchText isEqualToString:@""] && searchText != nil){
req.predicate = [NSPredicate predicateWithFormat:@"(places.placeTitle contains %@) OR (places.details contains %@) OR (name contains %@)", searchText, searchText, searchText];
NSLog(@"ModelHelper.getResults: Search text given, creating predicate: %@", req.predicate);
}
req.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
NSFetchedResultsController *controller = [[NSFetchedResultsController alloc]initWithFetchRequest:req
managedObjectContext:context
sectionNameKeyPath:nil
cacheName:nil];
NSError *error = nil;
[controller performFetch:&error];
そこにあるはずのない一致を受け取りました。たとえば、次のようになります。
searchText = "1234"
最初の結果は次のとおりです。
category[0].name = "Bars"
category[0].places[0].placeTitle = "Aaa"
category[0].places[0].details = "Aaa"
category[0].places[1].placeTitle = "123456"
category[0].places[1].details = "123456"
category[0].places[2].placeTitle = "test"
category[0].places[2].details = "test"
述語に何か問題がありますか? ありがとう。