when I try to Save an updated managedobject the changes don’t get persisted to the sqlite db.
In the appDelegate I create the managedObjectContext etc and I am passing a ref to this to the detailviewcontroller in which the update takes place.
I wonder whether this is root cause of the issue – can anyone please advise on this?
Thanks.
-(void)saveManagedObject:(id)sender
{
NSManagedObjectContext *context = [self managedObjectContext]; // this was passed earlier
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"jobDescription = %@", self.jobDescription.text ];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Job" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:predicate ];
Job *reqJob = [[context executeFetchRequest:fetchRequest error:&error] lastObject];
[reqJob setSummary:self.summary.text];
if (![context save:&error]) {
NSLog(@"Error updating %@ - error:%@",self.detailItem.jobDescription, error);
}
}
OK, I’ve solved the problem and in case anyone experiences the same I’ll detail the solution here.
It turns out that I hadn’t created the Job NSManagedObject class correctly (or I changed it at some point to make it fail to function).
As a consequence it seems that perhaps Core Data was unable to detect that a change had occurred in the object and therefore did not write anything back to the database.
I regenerated the class for this managedobject entity via XCode and all is well.
Thanks for looking at my post R.A. – sorry that it was a bit of a waste for you.