Reputation: 17715
Current Approach
Problem
Question
Upvotes: 3
Views: 2761
Reputation: 126157
Everything you can do graphically in the Core Data model editor you can do using the classes Core Data provides for creating/introspecting a managed object model. For this use case, you can use NSEntityDescription
to look up an entity, its properties
or propertiesByName
accessors to find the NSAttributeDescription
for the attribute you're interested, and setDefaultValue:
to do the same thing the Core Data model editor does.
You might find this the most appropriate way to do what you're looking for. Or, as @DimitryShevchenko notes, you can initialize values in your NSManagedObject
subclass' awakeFromInsert
method -- which way you choose might depend on your workflow or other requirements of your application.
Upvotes: 4
Reputation: 32424
You can subclass your NSManagedObject and set default values in awakeFromInsert
Related docs (see Object Life-Cycle)
Upvotes: 3