nsfetchRequests 반환 할 때 0 결과를 반환합니다 1
-
20-09-2019 - |
문제
엔티티를 삽입 한 후 핵심 데이터에 대한 페치를 수행하려고 노력하고 있으며 0 결과를 얻습니다. 나는 사람 엔티티가 있는데, Datamodule GUI에서 술어와 함께 페치 요청을 작성했습니다.
이름 == "개인 이름"
이름을 검색하기 직전에 삽입하고 저장합니다. 그리고 나는 테이블에 이름을 표시하고 응용 프로그램을 다시 열고 다시 열면 Coredata가 저장되기 때문에 작동한다는 것을 알고 있습니다.
다음은 내가 페치를 코딩 한 코드입니다. 내가 왜 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;
}
문제 해결을 도와주세요. 감사
해결책
술어 템플릿에서 :
name == "PERSONNAME"
해야한다:
name == $PERSONNAME
제휴하지 않습니다 StackOverflow