Created
October 11, 2010 22:05
-
-
Save wess/621315 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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