Skip to content

Instantly share code, notes, and snippets.

@mikker
Created February 7, 2011 01:20
Show Gist options
  • Save mikker/813890 to your computer and use it in GitHub Desktop.
Save mikker/813890 to your computer and use it in GitHub Desktop.
NSManagedObject with Rails-ish timestamps
//
// 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
//
// 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