나는 이것이 왜 작동하지 않는지 알아 내려고 노력하고 있습니다.CoreData 관계 검색하기
Quote
Customer
Quote
은 단순히 'customer
'라는 Customer
와 일대일 관계 속성이 있습니다 :
나는 두 개의 엔티티가 있습니다. 고객에게 CoreData objectID
(분명히)이 있습니다. 나는 모든 견적을 검색하고, Customer
objectID
을 기반으로하는 특정 고객을 가진 고객을 반환하려고합니다. 나는이 그럭저럭 한 모든 튜토리얼을 통해 읽기하지만 충돌 점점 계속 :
+ (void)fetchQuotesForCustomerID:(NSManagedObjectID*)objectID results:(void(^)(NSError* error, NSArray *fetchedResults))completion {
NSManagedObjectContext *context = [[QuoteGenerator sharedGenerator] managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Quote"
inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"customer.objectID == %@", objectID];
[fetchRequest setPredicate:predicate];
NSError *error;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
if (error) {
NSLog(@"fetch error = %@", [error localizedDescription]);
completion(error, nil);
} else {
NSLog(@"fetch count = %d", fetchedObjects.count);
completion(nil, fetchedObjects);
}
}
출력 오류 :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath customer.objectID not found in entity <NSSQLEntity Quote id=13>'
는 프리디 설정이 잘못인가? 문서를 읽으면 도트 구문을 사용하여 술어의 속성에 액세스 할 수 있다고 나와 있습니다.
도와주세요 ...
한 고객이 많은 견적을 가질 수있는 이유는 일대 다 많은 관계를 사용하지 않고 핵심 데이터를 사용하여 관련 견적 객체를 찾는 이유가 무엇입니까? – Gary
@Gary 귀하의 도움에 감사드립니다. 저를 올바른 답으로 인도하십시오! – random