我只是試圖圍繞核心數據包頭。我已經設法加載一些數據到我applicationDidFinishLaunching,但現在我想做一些更復雜的事情。當我從視圖控制器B退回到viewController A時,我想將recipeName從B發送回A,然後將其寫入核心數據。我得到這個錯誤:CoreData錯誤如何將核心數據寫回
CoreData: error: Failed to call designated initializer on NSManagedObject class 'Recipe' 2013-11-01 19:10:07.886 RecipesWithCore[96409:70b] -[Recipe setRecipeName:]: unrecognized selector sent to instance 0x8c8cf40 2013-11-01 19:10:07.890 RecipesWithCore[96409:70b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Recipe setRecipeName:]: unrecognized selector sent to instance 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'不是您的託管對象子類的屬性... –