I’m learning about how to compare NSDate objects with the isEqualToDateDate method. I don’t get why this simple test does not return true and print out the NSLog. Thanks in advance
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSDate *myDate = [[NSDate alloc]initWithTimeIntervalSinceNow:4000000];
NSDate *otherDate = [[NSDate alloc]initWithTimeIntervalSinceNow:4000000];
NSLog(@"myDate %@",myDate);
NSLog(@"otherDate %@",otherDate);
if ([myDate isEqualToDate:otherDate]) {
NSLog(@"The dates are the same");
};
[myDate release];
[otherDate release];
[pool drain];
return 0;
}
I believe, and this may be wrong, that since you are using
initWithTimeIntervalSinceNowthat the objects are being allocated at slightly different times, thus making them unequal.