gpt4 book ai didi

iphone - 核心数据/NSFetchedResultsController错误

转载 作者:行者123 更新时间:2023-12-03 18:54:25 25 4
gpt4 key购买 nike

我在使用核心数据/NSFetchedResultsController 时遇到了一些问题。我不完全确定错误在哪里,因为消息非常模糊。

当获取的结果 Controller 未获取任何对象时,我在插入多个对象时遇到问题。如果我尝试插入多个尚未获取任何对象的对象,则以下代码将崩溃并出现以下错误。如果我用它插入一个对象,它不会崩溃,如果已经提取了对象,它也不会崩溃。

崩溃发生在 save: 方法上。 NSArray 中的标题,在本例中它包含 5 个字符串。

Serious application error. Exception was caught during Core Data change processing: * -[NSCFArray objectAtIndex:]: index (4) beyond bounds (1) with userInfo (null) * Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (4) beyond bounds (1)'

NSEnumerator *titleEnumerator = [titles objectEnumerator];
NSString *title;
NSMutableArray *tasks = [NSMutableArray array];
Todo *todo;

while(title = [titleEnumerator nextObject])
{
todo = (Todo *)[NSEntityDescription insertNewObjectForEntityForName:@"Todo" inManagedObjectContext:managedObjectContext];
todo.title = title;
todo.state = [NSNumber numberWithInteger:TodoStateIncomplete];
todo.priority = [NSNumber numberWithInteger:TodoPriorityNormal];
todo.timeStamp = [NSDate date];
todo.dueDate = [NSDate distantFuture];
}

NSError *error;

if(![managedObjectContext save:&error])
{
NSLog(@"Unresolved error %@ %@", error, [error userInfo]);
abort();
}

最佳答案

以下是 Marcus Zarra(《核心数据》一书的作者)的提示:

Core Data error when deleting row in tableView

“尝试中断 objc_exception_throw 并查看引发异常的方法。这应该有助于追踪它”

关于iphone - 核心数据/NSFetchedResultsController错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2025057/

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