I have my coredata working fine, but when I put a setValue inside an if, it doesn’t work,
this is the code>
-(void) salvalo {
StaffManagerAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *newDay;
newDay = [NSEntityDescription insertNewObjectForEntityForName:@"DaysAttendance"
inManagedObjectContext:context];
[newDay setValue:startday forKey:@"start"];
[newDay setValue:today forKey:@"datef"];
[newDay setValue:myNumber forKey:@"empID"];
[newDay setValue:myNumber2 forKey:@"intID"];
//[newDay setValue:internet forKey:@"sinch"];
NSError *error;
[context save:&error];
if ([internet isEqualToString:@"YES"] ) {
[self insertJson];
[newDay setValue:internet forKey:@"sinch"];
}
else {
[newDay setValue:@"NO" forKey:@"sinch"];
}
//[self.view removeFromSuperview];
[self dismissModalViewControllerAnimated:YES];
}
please note that when I use the code inside the if in the commented part
//[newDay setValue:internet forKey:@”sinch”];
, it saves normally that value (YES/NO) to the coredata, but inside the if, it doesnt work, even if I put al the delegate and context stuff inside the if,,
so what is the problem? how to fix it?
thanks a lot!
The line
[context save:&error];is before the if statements.You may be setting the new value properly, just not saving. The problem might just be this oversight.