logicaroma
4/8/2011 - 12:24 PM

CoreData.m

//CORE DATA
//FETCHING PROCESS SNIPPET

NSManagedObjectContext	  *sharedContext = [(AppDelegate_Shared *)[[UIApplication sharedApplication] delegate] managedObjectContext];
NSFetchRequest			*request = [[NSFetchRequest alloc] init];
NSEntityDescription		*entity  = [NSEntityDescription entityForName:@"Currency" inManagedObjectContext:sharedContext];

[request setEntity:entity];

currencies = [[NSArray alloc ] initWithArray:[sharedContext executeFetchRequest:request error:nil]];


//INSERTING PROCCESS	
if([currencies count] == 0){
  Currency *gbp = (Currency *)[NSEntityDescription insertNewObjectForEntityForName:@"Currency" inManagedObjectContext:sharedContext];
            gbp.name = @"British Pounds";
            gbp.code = @"GBP";
		
  [sharedContext save:nil];
}