12

Documents 목록을로드 할 때 술어와 함께 NSFetchedResultsController을 사용하고 있습니다. 현재 활성화 된 것을 제외한 모든 Documents을로드하고 싶습니다.핵심 데이터 : 키 객체 "objectID"가 엔티티에 없습니다.

Rentzsch의 MOGenerator을 사용하여 _Document 클래스를 만든 다음 Document 하위 클래스에 내 모든 사용자 지정 코드를 넣습니다. _DocumentDocumentID 유형의 objectID 속성을 생성합니다. 컨트롤러 자체에

controller.currentDocID = self.document.objectID; 

, 나는 게으른 부하과 같이 fetchedResultsController :

- (NSFetchedResultsController *)fetchedResultsController { 
    if (fetchedResultsController != nil) { 
     return fetchedResultsController; 
    } 

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Document" inManagedObjectContext:managedObjectContext]; 
    [fetchRequest setEntity:entity]; 

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(objectID != %@)", self.currentDocID]; 
    [fetchRequest setPredicate:predicate]; 

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"dateModified" ascending:NO]; 
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; 

    [fetchRequest setSortDescriptors:sortDescriptors]; 

    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"]; 
    aFetchedResultsController.delegate = self; 
    self.fetchedResultsController = aFetchedResultsController; 

    [aFetchedResultsController release]; 
    [sortDescriptor release]; 
    [sortDescriptors release]; 

    return fetchedResultsController; 
} 

fetchedResultsController로드 컨트롤러를 생성하는 클래스에서

, 나는 컨트롤러의 currentDocID 속성을 설정 내 응용 프로그램이 처리되지 않은 예외로 인해 충돌합니다.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath objectID not found in entity <NSSQLEntity Document id=1>' 

모든 NSManagedObjects 임시 또는 영구 여부를 objectID가 내 이해합니다. 그렇지 않은가요? 이견있는 사람?

답변

10
currentDoc 현재 문서를 나타내는 NSManagedObject의 인스턴스에 대한 참조입니다

[NSPredicate predicateWithFormat:@"self != %@", [self currentDoc]] 

을 읽도록 조건을 변경

.

코어 데이터는 내부적으로 등호 검사를 수행합니다.

+2

'... @ "self! = % @", [self currentDoc]]'가'... @ "(objectID! = % @)와 같지 않은 이유를 알고 계십니까?, self.currentDocID] '. 이 게시 http://stackoverflow.com/a/2306550/647644에 따르면 그것은 동등해야합니다. – Lindemann

+0

@Lindemann 새로운 질문을 대신 작성하면 가장 좋습니다. –

관련 문제