I'm trying to edit a property on a managed object, but for some reason the changes aren't being saved. I'm using the following code:
If I NSLog the value "active" then it shows up as being toggled, but it doesn't save. Anybody know what's happening?
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 3) {
NSManagedObjectContext *context = [[self appDelegate] managedObjectContext];
NSNumber *num = [self.word valueForKey:@"active"]; // "word" is a managed object
if ([num isEqualToNumber:[NSNumber numberWithInt:1]]) {
num = [NSNumber numberWithInt:0];
} else {
num = [NSNumber numberWithInt:1];
}
[self.delegate wordWillBecomeInactive:self.word]; // Just a little protocol I wrote
[self.word setValue:num forKey:@"active"];
NSLog(@"%i", [context hasChanges]); // Prints 0
NSLog(@"%@", [self.word changedValues]); // Prints an empty dictionary
NSError *error = nil;
[context save:&error];
[self.tableView reloadData];
}
}
If I NSLog the value "active" then it shows up as being toggled, but it doesn't save. Anybody know what's happening?