[swift-evolution] [Proposal Draft] partial initializers

Brent Royal-Gordon brent at architechies.com
Tue Jan 12 14:23:01 CST 2016

>> I was about to post this idea (although I was going to suggest `partial func`, and possibly giving the `partial` keyword a parenthesized list of the properties that it expects to be initialized before you call it).
> How common do you think it would be for a partial init to need to require that some properties already be initialized.  Do you think that is important right away or do you think it's ok to start without it and enhance the feature later if we run into common needs for it?  I lean towards this as a possible enhancement rather than an immediate requirement.

I think that many, possibly most, partial methods—especially those that are meant to be called as normal methods will need to access existing properties, and the compiler will need to make sure partial method calls are ordered such that everything needed is already initialized; it's simply a question of whether we declare what's needed or automatically detect it. I've noticed in previous proposals that scanning the method body is disfavored, so I figure that's not our best bet here.

(On the other hand, if we don't declare required properties, I guess that might leave `partial(only)` to indicate a method that initializes a constant and thus can't be called except in a designated initializer.)

Brent Royal-Gordon

More information about the swift-evolution mailing list