gpt4 book ai didi

ios - 奇怪的问题 - "The fetched object at index x has an out of order section name"

转载 作者:可可西里 更新时间:2023-11-01 04:47:10 25 4
gpt4 key购买 nike

我收到以下错误消息:

CoreData: error: (NSFetchedResultsController) The fetched object at index 5 has an out of order section name 'James. Objects must be sorted by section name'
Unresolved search error Error Domain=NSCocoaErrorDomain Code=134060 "The operation couldn’t be completed. (Cocoa error 134060.)" UserInfo=0xaa07530 {reason=The fetched object at index 5 has an out of order section name 'James. Objects must be sorted by section name'}, {
reason = "The fetched object at index 5 has an out of order section name 'James. Objects must be sorted by section name'";
}

我已经在 SO 上浏览了无数答案,大多数最终指向使用不区分大小写的比较作为答案,但是正如您在下面看到的,我的获取请求已经设置为执行此操作:

<NSFetchRequest: 0xc082bd0> (entity: InviteeModel; predicate: (eventId == 148 AND typeOf != "InviteeTypeOfServerContact"); sortDescriptors: ((
"(lastName, ascending, caseInsensitiveCompare:)",
"(firstName, ascending, caseInsensitiveCompare:)"
)); batch size: 1000; type: NSManagedObjectResultType; )

我似乎已经将范围缩小到我有两个姓氏相同的受邀者(即 HENRY JAMES 和 Henry James)的情况,然后我得到上面的错误,说 James 不正常。如果我将两个姓氏都更改为 James 或 JAMES 那么它有效吗?!?!?

这是创建获取请求的代码:

NSFetchRequest *fetchRequest = [self buildFetchRequest];

// We have to reset the fetched results controller if the sort changes.
// Because otherwise the scrolling index will be inaccurate.
if (self.fetchedResultsController) {
if (![self.fetchedResultsController.sectionNameKeyPath isEqualToString:self.sortBy]) {
self.fetchedResultsController = nil;
}
}


if (!self.fetchedResultsController) {

NSManagedObjectContext *context = self.event.managedObjectContext;

NSString *sectionNameKeyPath = nil;
if (self.sortBy == DefaultSortBy) {

sectionNameKeyPath = @"sectionChar";
}
else {

sectionNameKeyPath = self.sortBy;
if ([self.sortBy isEqualToString:@"rsvpState"] || [self.sortBy isEqualToString:@"checkedIn"]) {
sectionNameKeyPath = @"lastName";
}
}

NSFetchedResultsController *fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:context
sectionNameKeyPath:sectionNameKeyPath
cacheName:nil];
fetchedResultsController.delegate = self;
self.fetchedResultsController = fetchedResultsController;

这是来自 buildFetchRequest 的一段,它添加了 sortDescriptors:

        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:self.sortBy
ascending:self.shouldSortAscending
selector:@selector(caseInsensitiveCompare:)];

// Add the default sorts (last, first).
NSSortDescriptor *lastSort = nil;
NSSortDescriptor *firstSort = nil;
if (![self.sortBy isEqualToString:@"lastName"]) {
lastSort = [NSSortDescriptor sortDescriptorWithKey:@"lastName"
ascending:YES
selector:@selector(caseInsensitiveCompare:)];
}
if (![self.sortBy isEqualToString:@"firstName"]) {
firstSort = [NSSortDescriptor sortDescriptorWithKey:@"firstName"
ascending:YES
selector:@selector(caseInsensitiveCompare:)];
}

NSArray *sorts = nil;

if (lastSort && firstSort) {
sorts = [[NSArray alloc] initWithObjects:sortDescriptor, lastSort, firstSort, nil];
}
else if (lastSort) {
sorts = [[NSArray alloc] initWithObjects:sortDescriptor, lastSort, nil];
}
else {
sorts = [[NSArray alloc] initWithObjects:sortDescriptor, firstSort, nil];
}

[fetchRequest setSortDescriptors:sorts];

任何想法,这让我发疯。

最佳答案

您正在设置与第一个排序描述符键不同的获取结果 Controller 部分名称键路径。

   NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] 
initWithKey:self.sortBy
ascending:self.shouldSortAscending
selector:@selector(caseInsensitiveCompare:)];

关键是self.sortBy

if ([self.sortBy isEqualToString:@"rsvpState"] || 
[self.sortBy isEqualToString:@"checkedIn"]) {
sectionNameKeyPath = @"lastName";
}

不是self.sortBy

这应该会导致您看到的错误。

关于ios - 奇怪的问题 - "The fetched object at index x has an out of order section name",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18343312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com