Another way to do this is to create a custom implementation of date + (NSDate *). You can use this class method using JRSwizzle . Create a small category for NSDate:
static NSTimeInterval seconds = 1300000000;
@interface NSDate (Fixed)
+ (NSDate *)fixedDate;
@end
@implementation NSDate (Fixed)
+ (NSDate *)fixedDate
{
return [NSDate dateWithTimeIntervalSince1970:seconds];
}
@end
Then in the code where you want to have a fixed date, do the following:
NSError *error;
[NSDate jr_swizzleClassMethod:@selector(date) withClassMethod:@selector(fixedDate) error:&error];
NSLog(@"Date:%@", [NSDate date]);
The magazine prints this:
2011-09-01 11:35:27.844 tests[36597:10403] Date:2011-03-13 07:06:40 +0000
source
share