[swift-evolution] [Proposal Draft] partial initializers

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



Sent from my iPad

> On Jan 12, 2016, at 2:00 AM, David Owens II <david at owensd.io> wrote:
> 
> 
>> On Jan 11, 2016, at 9:49 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
>> 
>> 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)
>> 	}
> 
> True, but that is a bit awkward, especially if there are multiple lets you want to initialize. It could also expose implementation details in the case of being able to reset the data from the call as some of the `let` could potentially be private.
> 
> Also, Matthew, it would probably be good to remove the forwarding stuff from this proposal. The idea of these helper-type initializers really doesn’t need to be coupled with that to stand on its own.

This could be done, but I believe it will be very common to just forward to a partial init.  Allowing that to be done concisely is important enough to be part of the core proposal.  I am removing any mention of general forwarding though so this proposal will stand on its own.

Matthew

> 
> -David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160112/76470ab9/attachment.html>


More information about the swift-evolution mailing list