Reputation: 2864
How could I go about doing this programmatically? Subclass NSManagedObject and override -(void)awakeFromInsert;
? Then I suppose set the attribute values in the methods implementation?
Upvotes: 0
Views: 65
Reputation: 17218
The way to get Core Data to do this, and IMO the right way to handle the situation, is to add another version of the model with the default values set on those properties, and configure automatic model migration.
I don't know whether migration will apply the new defaults to existing entities with nil values. (My guess would be not. Testing would bear the answer.)
Is there some reason you need to leave alone existing entities with nil values?
-awakeFromInsert
would indeed be the right place to do this kind of thing in code.
Upvotes: 1