My Locations: why does option PhotoID default to zero?

Hi folks, quick one…

Why is it that when you instantiate a new Location object the photoID? property gets a default value of zero rather than remaining nil?

Is this a quirk of being @NSManaged?


Hey @flanker, I believe this comes down to how you have configured the entity in the managed object model… It states the following on page 1314 of the book:

Open the Data Model editor. Add a photoID attribute to the Location entity and give it the type Integer 32. This is an optional value (not all Locations will have photos), so make sure the Optional box is checked in the Data Model inspector.

IIRC, if you don’t do this then it will have a default value of zero and that might be what you are seeing? You can also check in the inspector that the “default” field is empty.

Does that help?

Thanks for the response.

I did work it out at the time, and iirc I think it was a case that, although I’d had it as an optional, Xcode for some reason had put in a default value of zero.

I’ll check the code later to verify.


1 Like

I think that you should uncheck default validation Value in Data Model inspector.

This topic was automatically closed after 166 days. New replies are no longer allowed.