Skip to content

Instantly share code, notes, and snippets.

@wess
Created October 11, 2010 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wess/621315 to your computer and use it in GitHub Desktop.
Save wess/621315 to your computer and use it in GitHub Desktop.
- (void) awakeFromNib
{
[super awakeFromNib];
CDTest_AppDelegate *appDelegate = (CDTest_AppDelegate *)[[NSApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
Account *account = (Account *)[NSEntityDescription insertNewObjectForEntityForName:@"Account" inManagedObjectContext:context];
account.username = @"wess";
NSError *error = nil;
if(![context save:&error])
{
NSLog(@"Error: %@, %@", [error description], [error userInfo]);
exit(0);
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Account" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *results = [context executeFetchRequest:fetchRequest error:&error];
Account *a = [results objectAtIndex:2];
NSLog(@"Results: %@", a.username);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment