Skip to content

Instantly share code, notes, and snippets.

@yasirmturk
Created November 30, 2011 07:31
Show Gist options
  • Save yasirmturk/1408338 to your computer and use it in GitHub Desktop.
Save yasirmturk/1408338 to your computer and use it in GitHub Desktop.
A generic core data function that inserts a new row for the given entity & fill that row with given key/values
/*
* A generic function that inserts a new row for the given entity and fill that row with given key/values
*/
-(void)insertObjectForEntity:(NSString *)entityName objectsToInsert:(NSDictionary *)dictObjects
{
NSError *error;
NSManagedObject *objToInsert = [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:[self managedObjectContext]];
for (id key in [dictObjects allKeys]) {
[objToInsert setValue:key forKey:[dictObjects objectForKey:key]];
}
[[self managedObjectContext] save:&error];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment