简体   繁体   中英

Error in [NSFetchedResultsController performFetch]

I get the following error when I call [self.fetchedResultsController performFetch].

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSFileManager fileSystemRepresentationWithPath:]: conversion failed for /Users/ivanevf/Library/Application Support/iPhone Simulator/5.1/Applications/0EF75071-5C99-4181-8D4D-4437351EC1F4/Library/Caches/.CoreDataCaches/SectionInfoCaches/0

It's the first call I make on the controller after initializing it. The initialization looks like this:

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

// Create and configure a fetch request with the Book entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Conversation" inManagedObjectContext:self.objectContext];
[fetchRequest setEntity:entity];

// Create the sort descriptors array.
NSSortDescriptor *msgAgeDescriptor = [[NSSortDescriptor alloc] initWithKey:@"message" ascending:NO comparator:^NSComparisonResult(id obj1, id obj2) {
  // some code
}];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:msgAgeDescriptor, nil];

[fetchRequest setPredicate:[self fetchPredicate]];
[fetchRequest setSortDescriptors:sortDescriptors];
NSString *cacheName = [NSString stringWithFormat:@"%d%Conversation%d", self.viewType, self.location.bid];
// Create and initialize the fetch results controller.
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.objectContext sectionNameKeyPath:nil cacheName:cacheName];
_fetchedResultsController.delegate = self;

return _fetchedResultsController;
}

Any idea what's happening here? Thanks!

ps a couple of random things i tried: 1. removing the app directory from the emulator. (/Users/ivanevf/Library/Application Support/iPhone Simulator/5.1/Applications/0EF75071-5C99-4181-8D4D-4437351EC1F4) 2. commenting out the setPredicate, setSortDescriptors lines method calls

Looks like you have an extra escape character in cacheName . Try:

NSString *cacheName = [NSString stringWithFormat:@"%dConversation%d",
                                                 self.viewType,
                                                 self.location.bid];

I try this, NSString *cacheName = [NSString stringWithFormat:@"%d%Conversation%d", 1, 2]; and it throw out: 1onversation9283099

It is a regular string ,nothing strange.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM