4

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.

jaishankar
  • 249
  • 1
  • 4
  • 13

1 Answers1

6

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.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • Thanks Mundi for your answer. By mandatory do you mean I should simplay uncheck "Optional" right ? Is there any of the other options (especially "Indexed") should be selected ? – jaishankar May 08 '14 at 18:17
  • Right, this is how mandatory is achieved in the model editor: uncheck "Optional". Indexed really has nothing to do with this. Check it if you need fast lookups for this attribute. – Mundi May 08 '14 at 22:23