CoreData错误如何写回核心数据

时间:2013-11-01 23:15:48

标签: ios core-data nsmanagedobject

我只是试图围绕核心数据。我设法将一些数据加载到applicationDidFinishLaunching中,但现在我想做一些更复杂的事情。当我从视图控制器B退回到viewController A时,我想将recipeName从B发送回A,然后将其写入核心数据。我收到这个错误:

  

CoreData:错误:无法在NSManagedObject类'Recipe'上调用指定的初始值设定项   2013-11-01 19:10:07.886 RecipesWithCore [96409:70b] - [Recipe setRecipeName:]:无法识别的选择器发送到实例0x8c8cf40   2013-11-01 19:10:07.890 RecipesWithCore [96409:70b] * 由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [Recipe setRecipeName:]:无法识别的选择器发送到实例0x8c8cf40 “

这是我的unwindToRecipes:

-(IBAction) unwindToRecipes:(UIStoryboardSegue *)segue{
    DBKAddRecipeViewController *source = [segue sourceViewController];

    NSString *rn = source.recipe.recipeName;
    if (recipe != nil){
        //Add the recipe to coredata

        NSManagedObjectContext *context = [self managedObjectContext];
        NSManagedObject *newRecipe = [NSEntityDescription
                                   insertNewObjectForEntityForName:@"Recipe"
                                   inManagedObjectContext:context];

        [newRecipe setValue:rn forKey:@"recipeName"];

    }
}

1 个答案:

答案 0 :(得分:0)

似乎insertNewObject会返回Recipe类,而不是NSManagedObject。检查你的Recipe类,确保在@interface中有正确的声明,以及@implementation中的@dynamic recipeName。还要检查您的托管对象模型,并确保属性名称确实为recipeName