エンティティを挿入した後、コア データのフェッチを実行しようとしましたが、結果が 0 になりました。私は Person Entity.And を持っています。DataModule GUI で次の述語を使用してフェッチ要求を作成しました。
名前 == "人名"
名前を検索する直前に、最初に挿入して保存します。テーブルに名前を表示し、アプリケーションを閉じて再度開いた後にコアデータが保存されるため、それが機能することを知っています。
フェッチ用にコーディングしたコードは次のとおりです。0 の結果が得られる理由を理解するのを手伝ってください
-(Person *)findPersonByName:(NSString *)name{
NSLog(@"looking for person with name: %@",name);
NSDictionary *subs = [NSDictionary dictionaryWithObject:name forKey:@"PERSONNAME"];
NSAssert(self.managedObjectModel, @"anything wrong with managedObjectModel");//no
NSFetchRequest *fetch = [self.managedObjectModel fetchRequestFromTemplateWithName:@"getPersonByName" substitutionVariables:subs];
NSAssert(fetch, @"anything wrong with fetch?");//no
NSLog(@"fetch: %@",fetch);
NSError *error;
NSArray *result = [self.managedObjectContext executeFetchRequest:fetch error:&error];
NSLog(@"fetch request getQuestionsByParent: %u found (sub variables:%@, results:%@)", [result count], subs, result);
if (result == nil){
// Deal with error...
}
else if([result count]>0){
for (Person *person in result) {
NSLog(@"search result: %@",person.name);
}
}
return nil;
}
問題の解決にご協力ください。ありがとう