Don't check off? Should i or should i not check the checkmark.? So in one of my iOS app, i check login for an employee. Then save the employee entity in core data. Next time if my app is launched i bring the saved values and use those values to check login. I tried to that here in cocoa, but it was not possible. I used managedobjectcontext to save like i did in core data in iOS application
Code:
ITMLoginResult *loginResult = (ITMLoginResult *)[self.theParser.loginResultArray objectAtIndex:0];
NSLog(@"the empid gotten is %@",loginResult.empID);
NSLog(@"the secure hash is %@",loginResult.secureHash);
NSError *fetchError = nil;
NSFetchRequest *fR = [[NSFetchRequest alloc]init];
fR.entity = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:self.moc];
fR.predicate = [NSPredicate predicateWithFormat:@"employeeID == %@",loginResult.empID];
NSArray *tmpArray = [self.moc executeFetchRequest:fR error:&fetchError];
NSLog(@"the tmpArray count is %d",tmpArray.count);
if (tmpArray.count == 1)
{
Employee *empl = [tmpArray objectAtIndex:0];
NSLog(@"the employee exists %@",empl.employeeID);
NSLog(@"the secure hash for him is %@",empl.empHash);
}
int empID = [loginResult.empID intValue];
Employee *emp = (Employee *)[NSEntityDescription insertNewObjectForEntityForName:@"Employee" inManagedObjectContext:self.moc];
emp.employeeID = [NSNumber numberWithInt:empID];
emp.empHash = loginResult.secureHash;
[self.empArray addObject:emp];
NSError *error;
if (tmpArray.count ==0)
{
if(![self.moc save:&error])
{
NSLog(@"Failed to save the object");
}
else
{
NSLog(@"Save Successful");
}
}
So i parse an xml and save the values to an array "loginResultArray". I retrieve the same empID if it exists, but tmpArray is always 0. Then i save it using self.moc. I see the message "Save Successful".So whats happening to my data?