In my core data model on my entity I've created a "non-optional" relationship to another entity. When I have Xcode (Xcode 7 Beta 5) generate the NSManagedObject subclass, it's creating an attribute of type "NSSet?". Why is it making this attribute optional?
Why is Xcode creating an optional attr?
http://www.apple.com/legal/rfexposure/iPhone6,1/en/
It's optional because all properties default to nil in a Core Data model. Core Data's definitely of "optional" means that the value isn't required when you save your data to disk or to another context. That data can be missing (nil) throughout an entity's life cycle. That's a different concept than optionals in Swift, but it is unfortunate they share the same nomenclature.
This is the same explanation that the one provided here: http://stackoverflow.com/a/33552046/2681506 I understand the distinction between optional for Core Data and for Swift but I don't understand why a non-optional attribute with a default value (In the Entity pane of the Data Model inspector) is not generated as a non-optional with a default value... It's still auto generated as a Swift optional. So, how are we supposed to deal with optionals when we know for sure they have a value after a save? (Because non-optional + default value for Core Data). Should we guard ourself in each method that uses the managed object attributes to check if the value is nil or not?