Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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