Ios 我可以在创建FetchResultController对象后修改fetchRequest吗。?

Ios 我可以在创建FetchResultController对象后修改fetchRequest吗。?,ios,core-data,nsfetchrequest,Ios,Core Data,Nsfetchrequest,对不起,如果我不能很好地解释的话。 我有一个fetchResultController获取程序 如下- - (NSFetchedResultsController *)fetchedResultsController { if (_fetchedResultsController != nil) { return _fetchedResultsController; } NSFetchRequest *fetch

对不起,如果我不能很好地解释的话。 我有一个fetchResultController获取程序

如下-

- (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的一些谓词和属性(仅当需要时) 我的意思是我做了另一个这样的方法-

-(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>)"
“(实体:LibraryItem;id:0xdc208b0;数据:)”,
“(实体:LibraryItem;id:0xdc1c590;数据:)”,
“(实体:LibraryItem;id:0xdc1c5a0;数据:)”
问题是“数据:“”

这个代码有什么问题? 我做错什么了吗


谢谢你的帮助。

我在浪费了整整一天之后才意识到答案。 是的,我们可以修改

但是一旦你访问了数据,你就会找到正确的数据。 所以不必担心打印时是否显示错误数据

**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.**