8
'+ entityForName:nil不是合法的NSManagedObjectContext参数-核心数据
我已将所有相关代码添加到App Delegate中,并且能够添加到数据模型并从applicationDidFinishLaunchingWithOptions中的数据模型中获取。 当我尝试在View Controller中写入数据模型时,出现了我的问题。我已将此代码添加到头文件中: NSFetchedResultsController *fetchedResultsController; NSManagedObjectContext *managedObjectContext; @property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController; @property (nonatomic, retain) NSManagedObjectContext *managedObjectContext; 并将此代码添加到我的实现文件中: NSManagedObjectContext *context = [self managedObjectContext]; NSManagedObject *model = [NSEntityDescription insertNewObjectForEntityForName:@"Events" inManagedObjectContext:context]; [model setValue:@"Sample Event" forKey:@"eventName"]; NSError *error; if (![context save:&error]) { NSLog(@"Couldn't save: %@", [error localizedDescription]); } 但是,出现以下错误: 'NSInvalidArgumentException', reason: '+entityForName: …