我正在尝试使用获取请求设置NSFetchedResultsController
并且我一直收到错误:
“[NSSortDescriptor count]:无法识别的选择器发送到实例”
以下是我的代码。我的模型只有一条我想要获取的记录。此外,我正在关注Paul Heagarty的2010-2011 Core Data演示视频,以设置我的核心数据。
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Temple"];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
request.predicate = nil;
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.eventDatabase.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
答案 0 :(得分:0)
// CAUSE OF ERROR: Assigning NSSortDescriptor to a property that expects an NSArray
fetchRequest.sortDescriptors = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
// SOLUTION: Wrap your sort descriptor in an array, fixes error
fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];