Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default values of NSManagedObject attributes in Xcode

It is possible in Xcode to set empty string as default value of NSString type attribute? Or [NSDate date] as default value of NSDate type attribute?

like image 580
user500 Avatar asked Dec 21 '22 09:12

user500


1 Answers

You will have to do both programmatically. However, you can't let [NSDate date] be a default value (since at the time you would set that default value you are simply using the date at the specific time that you set the default value, not when the MO gets created).

You should create a subclass of NSManagedObject and implement the awakeFromInsert method:

- (void)awakeFromInsert
{
  [super awakeFromInsert];

  [self setDateAttribute:[NSDate date]];
  [self setStringAttribute:@""];
}
like image 65
Enchilada Avatar answered Jan 26 '23 01:01

Enchilada