Code:
NSManagedObjectContext *ctx = [[NSManagedObjectContext alloc] init];
[ctx setUndoManager:nil];
ITMAppDelegate *appDel = (ITMAppDelegate *)[[UIApplication sharedApplication] delegate];
[ctx setPersistentStoreCoordinator: [appDel persistentStoreCoordinator]];
//self.managedObjectContext = appDelegate.managedObjectContext;
ITMDistinctCustomers *distinctCustomer = (ITMDistinctCustomers *)[NSEntityDescription
insertNewObjectForEntityForName:@"ITMDistinctCustomers"
inManagedObjectContext:ctx];
distinctCustomer.name=@"Blah";
...
[self.distinctCustomerArray addObject:distinctCustomer];
NSError *error = nil;
if (![ctx save:&error])
{
NSLog(@"Failed to save distinct customer");
}
Last edited by a moderator: