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?
Asked
Active
Viewed 60 times
0

paulmelnikow
- 16,895
- 8
- 63
- 114

Skyler
- 2,834
- 5
- 22
- 34
1 Answers
1
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.

paulmelnikow
- 16,895
- 8
- 63
- 114
-
Oh, come to think of it, you are correct, I would need to update the default values of existing entities as well. – Skyler Jun 26 '13 at 00:06
-
I do know that if you set the properties as required, that migration will apply them to existing elements with nil values. – paulmelnikow Jun 26 '13 at 00:16
-
If this solved your problem, please click the check mark next to the answer to mark it accepted. – paulmelnikow Jun 26 '13 at 12:12