iphone core data loop array and save each

Posted by Matt Facer on Stack Overflow See other posts from Stack Overflow or by Matt Facer
Published on 2010-04-25T21:33:00Z Indexed on 2010/04/25 22:23 UTC
Read the original article Hit count: 280

Filed under:
|

I have a core data model with two tables (meal and ingredients). I am trying to save ONE meal with MANY ingredients. I have the code below which loops through an array of ingredients. I'm trying to save it, but I cannot redeclare the "entity" below. How do I do it? I've tried releasing it, but that didn't work! Thanks for any help.

 for (x=0;x<ingredients;x++) {
  NSEntityDescription *entity = [NSEntityDescription insertNewObjectForEntityForName:@"Ingredient" inManagedObjectContext:managedObjectContext];
  entity.name = @"test";
 }

(this method does work saving ONE record out of the loop.. so that's not the problem)

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about core-data