views:

61

answers:

2

Hi, Im using Core data. I have an entity with an attribute of type Date. Is there a way I can set Default Values as Current Date? (Like entering 'CURRENTDATE' or something in default value of the attribute?)

Thanks

+1  A: 

You can use "now" to get the current date.

Eric Fortin
+1  A: 

You could use "now" in the model, but Core Data evaluates that at compile time, not runtime. You'll get the date of compilation stored in your model defaults, which is probably not what you want:

http://iphonedevelopment.blogspot.com/2009/07/core-data-default-dates-in-data-model.html

The most reliable way to ensure a default property value of the current date is to override -awakeFromInsert in an NSModelObject subclass and assign the current date there.

- (void) awakeFromInsert 
{
   [super awakeFromInsert];
   self.date = [NSDate date];
}
Bill Garrison