Created
February 7, 2011 01:20
-
-
Save mikker/813890 to your computer and use it in GitHub Desktop.
NSManagedObject with Rails-ish timestamps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSManagedObjectWithTimestamps.h | |
// Brainbow Apps, 2011 | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSManagedObjectWithTimestamps : NSManagedObject { | |
NSDate *createdAt; | |
NSDate *modifiedAt; | |
} | |
@property (assign) NSDate *createdAt; | |
@property (assign) NSDate *modifiedAt; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSManagedObjectWithTimestamps.m | |
// Brainbow Apps, 2011 | |
// | |
#import "NSManagedObjectWithTimestamps.h" | |
@implementation NSManagedObjectWithTimestamps | |
@dynamic modifiedAt, createdAt; | |
- (void)willSave { | |
[self setPrimitiveValue:[NSDate date] forKey:@"modifiedAt"]; | |
if (![self primitiveValueForKey:@"createdAt"]) | |
[self setPrimitiveValue:[NSDate date] forKey:@"createdAt"]; | |
[super willSave]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment