[swift-evolution] [Proposal Draft] partial initializers

Matthew Johnson matthew at anandabits.com
Tue Jan 12 09:09:07 CST 2016



Sent from my iPad

On Jan 11, 2016, at 11:49 PM, Brent Royal-Gordon <brent at architechies.com> wrote:

>> What I’m saying is that you don’t need the partial inits anymore, you still need some of your rules, but the actual “partial init” would be replaced by this modifier on functions.
>> 
>> Maybe something like this:
>> 
>>    initializer func reset() {
>>        value1 = 0
>>    }
>> 
>> The “initializer” modifier would be your “partial init” modifier.
> 
> 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.

Matthew
> 
>> For this to work though, you’d basically have to take the same limitation as convenience inits() today and disallow `let` values to be set. However, most of your other rules would apply to these.
> 
> Keep in mind that it's only the assignment itself that would have to be in the initializer. You could still use a partial method to encapsulate the logic used to calculate the constant's value:
> 
>    let foo: Foo
>    var bar: Bar
>    
>    init(bar: Bar) {
>        self.bar = bar
>        foo = makeFoo()
>        super.init()
>    }
>    
>    partial(bar) func makeFoo() -> Foo {
>        return Foo(bar: bar)
>    }
> 
> -- 
> Brent Royal-Gordon
> Architechies
> 


More information about the swift-evolution mailing list