I am trying to determine if I have a duplicate record in CoreData using MagicalRecord. To do that, I am comparing the updated data with the first existing record:
This is the code I am using to do the search:
// set up predicate to find single appointment
if(selectedApptKey.length > 0) {
NSPredicate *predicate = ([NSPredicate predicateWithFormat:
@"((aApptKey == %@) && (aStartTime == %@) && (aEndTime == %@) && (aServiceTech == %@))",
selectedApptKey, tStartDate, tEndDate, tStaff]);
NSLog(@"\n\nselectedApptKey: %@\ntStartDate: %@\ntEndDate: %@\ntStaff: %@",selectedApptKey, tStartDate, tEndDate, tStaff);
ai = [AppointmentInfo MR_findFirstWithPredicate:predicate inContext:localContext];
if((ai.aApptKey == selectedApptKey) &&
(ai.aStartTime == tStartDate) &&
(ai.aEndTime == tEndDate) &&
(ai.aServiceTech == tStaff)) {
updateFlag = YES;
}
}
This is the predicate data I am using to search for an existing record:
selectedApptKey: RolfMarsh3911 tStartDate: 2013-12-29 20:15:00 +0000 tEndDate: 2013-12-29 22:15:00 +0000 tStaff: Kellie
This is the resulting record as obtained from the above code:
Printing description of ai:
<NSManagedObject: 0xb705430> (entity: AppointmentInfo; id: 0xb7bca00 <x-coredata://649CD00C-3C88-4447-AA2B-60B792E3B25F/AppointmentInfo/p22> ; data: {
aApptKey = RolfMarsh3911;
aEndTime = "2013-12-29 22:15:00 +0000";
aImage = nil;
aNotes = "";
aPosH = 200;
aPosW = 214;
aPosX = 0;
aPosY = 231;
aServiceTech = Kellie;
aServices = "";
aStartTime = "2013-12-29 20:15:00 +0000";
client = nil;
})
As you can see, the record and search data are exact. Qustion is: why is the if statement failing (the updateFlag is not being set to YES)?