Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shouldn't even non-optional attributes be nullable? #396

Open
seanm opened this issue Oct 2, 2024 · 2 comments
Open

Shouldn't even non-optional attributes be nullable? #396

seanm opened this issue Oct 2, 2024 · 2 comments

Comments

@seanm
Copy link
Contributor

seanm commented Oct 2, 2024

In machine.h.motemplate we have:

@property (nonatomic, strong<$if Relationship.optional$>, nullable<$endif$>) <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;

i.e.:

  • optional relationships are nullable (makes sense!)
  • non-optional relationships are not nullable (does this make sense?)

In actuality, during deletion and tear down, even optional relationships get niled, and this can even be encountered during KVO observation. I have been bitten in the past assuming non-optional relationships are never nil.

Of course I can just use my own template, but we could consider changing the default template too.

Thanks for any thoughts on this...

@rentzsch
Copy link
Owner

rentzsch commented Oct 7, 2024

even optional relationships get niled

You mean non- optional here?

This is similar to the Garbage Collection Object Resurrection issue. The common case is you want non-optional to be non-nullable, expect for deletion, right?

For deletion, it may make sense to bypass the setters.

@seanm
Copy link
Contributor Author

seanm commented Oct 7, 2024

You mean non- optional here?

Yes, sorry, that made things more confusing!

I don't have an exact example on hand, but I'm pretty sure I recall being surprised encountering required relationships being nil, probably during undo, redo, KVO, faulting, or something like that.

I've just tried Xcode's own ManagedObject codegen, and it seems to make all relationships nullable, be they optional or required relationships.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants