I have performed the save operation in core data and it is successfully done .It stores the data .I have also fetched the data into the log. This is my code for fetching data in log but I dont know how to fetch this data in TableView.
NSError *error;
DemoAppCoreDataAppDelegate *appdelegate = (DemoAppCoreDataAppDelegate *)[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context = [appdelegate managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
NSEntityDescription *entity = [NSEntityDescription entityForName: @"Employee" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedobject = [context executeFetchRequest:fetchRequest error:&error];
tablearray = [[NSMutableArray alloc] initWithArray:fetchedobject copyItems:YES];
for (NSManagedObject *info in fetchedobject ) {
NSLog(@ "%@",[info valueForKey:@"name"] );
}
[fetchRequest release];
I would recommend to use a
NSFetchedResultsController.Apple provides complete sample code in the
NSFetchedResultsControllerdocumentationThe
NSFetchedResultsControlleris specifically designed to work in between a tableView and Core Data. It makes everything a lot easier.For example it will automatically insert and delete rows when you add or remove objects from the core data. For this you have to implement the
NSFetchedResultsControllerDelegateprotocol. The full sample code for this is in the protocol documentation