+ entityForName:nil不是合法的NSManagedObjectContext参数,用于搜索实体名称“Person”

时间:2017-02-09 12:14:20

标签: ios core-data

-(void)action_addInformation:(id)sender
    {
        NSLog(@"add person information");
        @try {

             AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
            context = [appDelegate manageObjectContext];

            NSEntityDescription *entityDescription=[NSEntityDescription entityForName:@"Person" inManagedObjectContext:context];
            NSManagedObject *newPerson=[[NSManagedObject alloc]initWithEntity:entityDescription insertIntoManagedObjectContext:context];
            [newPerson setValue:firstNameTxtField.text forKey:@"firstname"];
            [newPerson setValue:lastNameTxtField.text forKey:@"lastname"];

            NSError *error;
            [context save:&error];
            NSLog(@"Information added successfully");

        } @catch (NSException *exception) {
            NSLog(@"%@",exception);
        } @finally {

        }
        }

我使用Core Data作为使用objC语言的表格视图。它可以成功启动,但在AddView中单击完成按钮后,出现错误:

  

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'+ entityForName:nil不是合法的NSManagedObjectContext参数,用于搜索实体名称'Person'*

0 个答案:

没有答案