我嘗試檢查我的coredata存儲中是否有任何數據作爲我的應用程序的恢復類型。基本上,如果用戶處於最終視圖中,那麼他們會不斷更新coredata中的一些數據。Coredata錯誤setObjectForKey:對象不能爲零
因此,他們是在最後的看法,然後應用程序休息或他們把它睡覺,然後應用程序從內存中刪除。
當應用程序下次加載我檢查我的coredata對象,看看是否有任何值如果有我提示用戶告訴他們有未完成的工作,你想從你離開的地方拿起繼續新鮮。
如果他們想新開始,我會轉儲目前在我的核心數據中的任何東西,並允許他們工作。否則,我跳轉到最後一個視圖,加載在coredata中的數據並允許它們繼續工作。
但是,這是錯誤發生的地方我檢查我的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)'
任何幫助,將不勝感激。
什麼包含project.proj?錯誤是說不能爲零? – RFG
您的實體名稱錯誤,當您正在使用'@「Project」'製作'NSEntityDescription'時。它應該是'ProjectList'。 – TheTiger