Skip to content

Instantly share code, notes, and snippets.

@remear
Created April 14, 2010 16:26
Show Gist options
  • Save remear/366015 to your computer and use it in GitHub Desktop.
Save remear/366015 to your computer and use it in GitHub Desktop.
- (BOOL)insertNewObject
{
// Create a new instance of the entity managed by the fetched results controller.
NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
// If appropriate, configure the new managed object.
NSLog(@"%@", currentID);
[newManagedObject setValue:[currentID stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] forKey:@"id"];
// Save the context.
NSError *error = nil;
if (![context save:&error])
{
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
else
{
NSLog(@"saving entry");
}
return error == nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment