Over the past weeks I have been studying Restkit (v0.10.0) and the basic data and the possibilities are endless with these great tools. The problem is that I'm a little overwhelmed by how to see the big picture here. And due to the very fast update of Restkit, most of the tutorial / demo code is outdated and no longer works properly.
I managed to get my table view populated with data from my json on a remote server. I also developed how to make remote data master in combination with caching that works now, but I am struggling with NSManagedObjectContext / NSEntityDescription (master data) and how it works with Restkit when using POST commands.
If I understand correctly, the record is created in Core Data (after the comment line // Create a new instance), and after that this data is used to create a POST request so that the record is sent to the server.
This code is used to create a new record on the server, but when the code is executed (I see the record being created on my server), but my table view is not updated accordingly, the table view is not updated, and therefore the new record is first displayed when the application is restarted. Manually updating data from the server also does not help.
Hope someone can give me some pointers or maybe a tutorial with Restkit / core and POST data. Thank!
- (void)createGoalWithName:(NSString *)name andDescription:(NSString *)goalDescription
{
Goal* goal = [Goal object];
goal.identifier = 0;
goal.name = name;
goal.goalDescription = goalDescription;
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
[NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
[self saveContext];
[[RKObjectManager sharedManager].router routeClass:[Goal class] toResourcePath:@"/api/goals" forMethod:RKRequestMethodPOST];
[[RKObjectManager sharedManager] postObject:goal delegate:self];
[self.tableView reloadData];
}
- (void)saveContext {
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
source
share