<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">We considered a proposal I wrote early in the year. &nbsp;There was extensive discussion of the topic at that time. &nbsp;The core team decided to defer the topic at the time. &nbsp;Everyone was convinced there are better ways to handle it than I originally proposed (including myself). &nbsp;The topic will be revisited at some point in the future but is not in scope for Swift 4, phase 1.<div class=""><br class=""></div><div class="">If you wish to catch up on the discussion, here’s a link to the proposal which includes links to the discussion as well as the core team’s rationale for their decision on this proposal:&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0018-flexible-memberwise-initialization.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0018-flexible-memberwise-initialization.md</a><br class=""><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 10, 2016, at 7:27 AM, Guy Miller via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi,<br class=""><br class="">When I am defining a struct I find myself often using a style as shown in the following example:<br class=""><br class="">struct Foo {<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var greeting: String<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var x: Int<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var y: Int<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var z: Int<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>init(greeting: String, x: Int = 1, y: Int = 2, z: Int = 3) {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>self.greeting = greeting<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>self.x = x<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>self.y = y<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>self.z = z<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class="">}<br class=""><br class="">This enables one to write code when one doesn’t need to change defaults:<br class=""><br class="">let f = Foo(greeting: “Hello”)<br class=""><br class="">and when one wishes to change one of the defaults:<br class=""><br class="">let f = Foo(greeting: “Hello”, z: 4)<br class=""><br class="">It would be better if one could write the struct in what I understand is the preferred style:<br class=""><br class="">struct Foo {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var greeting: String<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var x = 1<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var y = 2<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var z = 3<br class="">}<br class=""><br class="">and have the compiler generate the initializer:<br class=""><br class="">init(name: String, x: Int = 1, y: Int = 2, z: Int = 3) {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>self.name = name<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>self.x = x<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>self.y = y<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>self.z = z<br class="">}<br class=""><br class="">rather than one where all the parameters that have a default value need to be specified in the initializer if one wishes to change just one of them.<br class=""><br class="">Regards,<br class="">Guy Miller<br class=""><br class=""><br class=""><br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></div></blockquote></div><br class=""></div></div></body></html>