我是新来的目标C,iOS和CoreData,我目前正试图保存一些数据到我的CoreData实体。+ entityForName:nil不是合法的NSManagedObjectContext参数搜索实体名称'分数'
当试图找到insertNewObjectForEntityForName
的实体时,它看起来像基于下面的错误返回nil
。
任何帮助将不胜感激!
错误:
2015-04-06 17:46:12.274 Bugland[18623:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Scores''
LeaderboardViewController.m
JPAppDelegate *JPAppDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context =[JPAppDelegate managedObjectContext];
NSManagedObject *newScore;
newScore = [NSEntityDescription
insertNewObjectForEntityForName:@"Scores"
inManagedObjectContext:context];
[newScore setValue: scoreToAddAsString forKey:@"score"];
NSError *error;
[context save:&error];
调试,检查'context'是否存在。崩溃前记录的任何错误? – Wain
检查价值和/或环境是否存在的最佳方法是什么?只需将它登录到控制台或? – JP89
当然,或者添加一个断点和'po' – Wain