To-Many Relationships defined as NSSet? not NSSet

Originator:brianaking
Number:rdar://27195283 Date Originated:06-Jul-2016 10:36 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 8 beta 2
Classification:UI/Usability Reproducible:Always
 
Summary:
To Many relationships are defined as NSSet? in the generated Core Data code. If there are no relationships, it is always represented as .Some(EmptySet), and never nil. If nil is assigned to the set (which I assume would break all of the relationships), and the property is queried immediately after, the property returns an empty set again. This behavior does not change based on the optional flag being set in the model.

I’d advocate that a nil relationship doesn’t make sense from a modeling perspective, and the current implementation behavior appears to agree. I’m not sure if having an optional relationship makes sense in some context that I’m not thinking of, but it appears to be more of a side effect of optional attributes in general. 

In the light of the generated code, an Optional relationship does not make sense to me. However I believe that the optionality of the NSSet should at least  align with the optionality of the relationship in the model file. Making the set non-optional would make the swift API much nicer to work with, and  would remove the not-so-clear use case of assigning nil to the set.

Steps to Reproduce:
Create an optional and non-optional To Many relationship in Core Data, and open the generated swift  code

Expected Results:
1) Non-Optional To-Many relationships should be represented as a Non-Optional set.

2) Optional To-Many relationships I believe should also be represented as a Non-Optional set since it always returns a set when queried. This would remove the behavior of being able to assign nil to clear out the relationship if that is still desired, but would match the current behavior otherwise. 

Behavior for #2 is not very important compared to the value of having non-optional relationships.

Actual Results:
An optional set is always generated

Regression:
Describe circumstances where the problem occurs or does not occur, such as software versions and/or hardware configurations.

Notes:
Provide additional information, such as references to related problems, workarounds and relevant attachments.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!