Reputation: 289
I need to have an attribute in Coredata's entity be set as not null and have a default value.
I have set a default value for the attribute of the Entity in the .xcdatamodeld schema definition
My question is Should the attribute be marked as Optional or not.
What will be the impact if I don't check any of the following three to the attribute - Transient, Optional, Indexed ? Will this attribute be treated as mandatory ?
EDIT: When I set the property as mandatory and if the value trying to set is nil, the insert fails with error code 1570 - NSValidationMissingMandatoryPropertyError, where I am simply expecting the property to be set its default value and gets inserted.
What is the point of having a default value then ? Can anyone help me what I am really missing here.
Upvotes: 4
Views: 3379
Reputation: 80273
Set it as mandatory and configure it with an appropriate default value (e.g. 0
). If it is optional, the setting of the default value is not guaranteed, regardless of the other options.
Upvotes: 6