I've got an if
routine that compares a value with two other values (using the || operator) and if the statement evaluates to YES
, the value firstActivity.stopTime
should change from null
to the current time [NSDate date]
.
However, it appears to evaluate to NO
, resulting in no change, even though my NSLog
readouts (and my own observations) appear to confirm that it would have to evaluate to YES
.
Here's the code:
-(void) compareActivity
{
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
TimedActivity *firstActivity = [TimedActivity MR_findFirstOrderedByAttribute:@"startTime" ascending:NO];
NSLog(@"1 Currently timed activity is %@",firstActivity.name);
NSLog(@"2 thisSpec.activityOfInterest is %@",self.thisSpec.activityOfInterest);
NSLog(@"3 Currently timed activity stopTime is %@",firstActivity.stopTime);
NSLog(@"4 thisSpec.benchmarkActivity is %@",self.thisSpec.benchmarkActivity);
if (firstActivity.name == self.thisSpec.activityOfInterest || firstActivity.name == self.thisSpec.benchmarkActivity)
{
firstActivity.stopTime = [NSDate date];
[localContext MR_saveToPersistentStoreAndWait];
NSLog(@"5 Currently timed activity stopTime is %@",firstActivity.stopTime);
}
NSLog(@"6 Currently timed activity stopTime is %@",firstActivity.stopTime);
}
Here's the readout from the console:
2014-04-28 22:15:06.588 WMDGx[5683:a0b] 1 Currently timed activity is Test 1
2014-04-28 22:15:06.588 WMDGx[5683:a0b] 2 thisSpec.activityOfInterest is Test 1
2014-04-28 22:15:06.589 WMDGx[5683:a0b] 3 Currently timed activity stopTime is (null)
2014-04-28 22:15:06.589 WMDGx[5683:a0b] 4 thisSpec.benchmarkActivity is Test 2
2014-04-28 22:15:06.589 WMDGx[5683:a0b] 6 Currently timed activity stopTime is (null)
Any ideas or suggestions?
Thanks!
Update:
I updated my code thusly:
if ([firstActivity.name isEqualToString:self.thisSpec.activityOfInterest] || [firstActivity.name isEqualToString:self.thisSpec.benchmarkActivity])
{
firstActivity.stopTime = [NSDate date];
[localContext MR_saveToPersistentStoreAndWait];
NSLog(@"5 Currently timed activity stopTime is %@",firstActivity.stopTime);
}
Now it works perfectly! Funny, I had run across this same issue once before some time back, and had actually tried changing the code, but this time I apparently did something wrong, leading me to think it was the wrong approach.
Many thanks!