2014-12-01 2 views
0

죄송합니다. 완벽하게 설명 할 수없는 경우. fetchResultController 게터가 있습니다.FetchResultController 객체를 만든 후 fetchRequest를 수정할 수 있습니까?

으로

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

     } 

     NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
     // Edit the entity name as appropriate. 
     NSEntityDescription *entity = [NSEntityDescription entityForName: self.entityName inManagedObjectContext:self.managedObjectContext]; 
     [fetchRequest setEntity:entity]; 

     // Set the batch size to a suitable number. 
     [fetchRequest setFetchBatchSize:20]; 

     // Edit the sort key as appropriate. 
     NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:keyColumnNamePid ascending:NO]; 
     NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; 

     [fetchRequest setSortDescriptors:sortDescriptors]; 


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

     self.fetchedResultsController.delegate = self; 

     // Perform Fetch on Result Controller 
NSError *error = nil; 
    if (![self.fetchedResultsController performFetch:&error]) { 
     // Replace this implementation with code to handle the error appropriately. 
     // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    }   
      return _fetchedResultsController; 
} 

가 지금은 fetchRequest의 일부 조건 및 속성을 설정하려는 below-. (이 필요한 경우에만.) 나는 this-

-(NSFetchedResultsController *) fetchResultsControllerWithPredicate:(NSPredicate *) predicate{ 

    [self.fetchedResultsController.fetchRequest setPredicate:predicate]; 

    [NSFetchedResultsController deleteCacheWithName:@"myCache"]; 


    NSError *error = nil; 
    if (![self.fetchedResultsController performFetch:&error]) { 
     // Replace this implementation with code to handle the error appropriately. 
     // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    } 

    return _fetchedResultsController; 
} 

처럼 다른 방법을 만든 의미 이제 인쇄 할 때 _PFBatchFaultingArray가 아래와 같이 반환됩니다. -

"<LibraryItem: 0xdc22150> (entity: LibraryItem; id: 0xdc208b0 <x-coredata://A1159A80-CA8B-4443-B96C-582BF0DC0290/LibraryItem/p332> ; data: <fault>)", 
    "<LibraryItem: 0xdc224d0> (entity: LibraryItem; id: 0xdc1c590 <x-coredata://A1159A80-CA8B-4443-B96C-582BF0DC0290/LibraryItem/p290> ; data: <fault>)", 
    "<LibraryItem: 0xdc22510> (entity: LibraryItem; id: 0xdc1c5a0 <x-coredata://A1159A80-CA8B-4443-B96C-582BF0DC0290/LibraryItem/p224> ; data:<fault>)" 

문제 : "data : '<'fault '>'"입니다.

이 코드의 문제점은 무엇입니까? 내가 잘못하고 있니?

도움 주셔서 감사합니다.

답변

0

나는 완전한 날을 낭비한 후에 답을 깨닫는다. 예 수정할 수 있습니다.

하지만 데이터에 액세스하면 올바른 데이터를 찾을 수 있습니다. 인쇄하는 동안 결함있는 데이터를 표시하는 경우 걱정하지 마십시오.

**When you just trying to print the values it will print a data : fault. 
Because CoreData fetch data on Demand, means while you are printing it, it is partial Data. 
When you access (you demand) the value, you find the complete data.** 
관련 문제