Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xcodeNewbie

macrumors member
Original poster
Jul 1, 2011
65
0
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:
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.