gpt4 book ai didi

iphone - Coredata错误setObjectForKey : object cannot be nil

转载 作者:行者123 更新时间:2023-12-03 19:51:39 26 4
gpt4 key购买 nike

我正在尝试检查我的核心数据存储中是否有任何数据作为我的应用程序的恢复类型。基本上,如果用户处于最终 View ,则 coredata 中会有一些数据不断更新。

因此,他们处于最终 View 中,然后应用程序崩溃,或者他们将其置于 sleep 状态,然后应用程序从内存中删除。

当应用程序下次加载时,我会检查我的 coredata 对象以查看是否有任何值。如果有,我会提示用户告诉他们还有未完成的工作,您想从上次中断的地方继续进行吗?

如果他们想重新开始,我会转储当前核心数据中的任何内容并允许他们工作。否则我会跳转到最后一个 View ,加载 coredata 中的数据并允许它们继续工作。

然而,这就是错误发生的地方,我像这样检查我的核心数据。

NSMutableArray *checkFinMutableArray = [coreDataController readFin];

if ([checkFinMutableArray count] > 0) {
//Show mesage, recover or not?
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:@"Selected projects avalible"];
[alert setMessage:@"It appears that you have unfinished projects from a previous session. Would you like to continue working on these projects?"];
[alert setDelegate:self];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
[alert show];
}

这就是我的 coredata 对象的样子

 - (NSMutableArray *)readFinDimensions {
NSManagedObjectContext *context = [self managedObjectContext];


NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Project" inManagedObjectContext:context];
[fetchRequest setEntity:entity];

NSError *error;

NSMutableArray *projectDictionaryArray = [[NSMutableArray alloc] init];


NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];


for (ProjectList *projectList in fetchedObjects) {

NSMutableDictionary *tempProjectDictionaryArray = [[ NSMutableDictionary alloc] init];

[tempProjectDictionaryArray setObject:project.proj forKey:@"Proj"]; // this is where the ap dies
[tempProjectDictionaryArray setObject:project.desc forKey:@"Desc"];

[projectDictionaryArray addObject:tempProjectDictionaryArray];
}

return projectDictionaryArray;
}

这就是错误的样子

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: Proj)'

任何帮助将不胜感激。

最佳答案

可能您的代码必须是:

    for (ProjectList *projectList in fetchedObjects) {

NSMutableDictionary *tempProjectDictionaryArray = [[ NSMutableDictionary alloc] init];

[tempProjectDictionaryArray setObject:projectList.proj forKey:@"Proj"]; // this is where the ap dies
[tempProjectDictionaryArray setObject:projectList.desc forKey:@"Desc"];

[projectDictionaryArray addObject:tempProjectDictionaryArray];
}

其中project.proj被projectList.proj更改(也适用于.desc)。

关于iphone - Coredata错误setObjectForKey : object cannot be nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19195878/

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