It really annoys me. In Objective-C, I have an object Itemwith a boolean attribute Deleted. I would like to be able to set the value Deletedto YES or 1.
This is my code:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Item" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSString *itemID = [[fetchedObjects objectAtIndex:(int)[currentTable selectedRow]] valueForKey:@"ItemID"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ItemID = %@", itemID];
[fetchRequest setPredicate:predicate];
NSError *error = nil;
Item *objectToDelete = [[managedObjectContext executeFetchRequest:fetchRequest error:&error] objectAtIndex:0];
if (objectToDelete == nil) {
NSLog(@"ERROR");
}
[fetchRequest release];
[objectToDelete setValue:[NSNumber numberWithBool:YES] forKey:@"Deleted"];
[managedObjectContext save:&error];
Something that needs to be noted is that I can successfully change different attributes; for example: I add the -DEL line at the end of the Item Codeand attributes Name. When I look at the data table, the rows for these values are updated accordingly, however the value for Deletedremains equal to 0.
source
share