【问题标题】:CoreData error how to write core data backCoreData错误如何写回核心数据
【发布时间】:2013-11-01 23:15:48
【问题描述】:

我只是想了解核心数据。我已经设法在 applicationDidFinishLaunching 中加载了一些数据,但现在我想做一些更复杂的事情。当我从视图控制器 B 回到视图控制器 A 时,我想将配方名称从 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"];

    }
}

【问题讨论】:

  • 看起来您的 RecipeName 不是您的托管对象子类的属性...

标签: ios core-data nsmanagedobject


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2012-01-20
    • 2011-06-05
    • 2011-10-30
    • 2014-07-05
    • 2012-03-28
    • 2012-02-16
    • 2010-12-19
    • 2011-01-02
    相关资源
    最近更新 更多