<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 29, 2015, at 5:25 PM, Charles Srstka &lt;<a href="mailto:cocoadev@charlessoft.com" class="">cocoadev@charlessoft.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Strong +1 on this proposal. I use Objective-C’s forwarding mechanisms quite often in my custom view code, in order to separate the code managing the outer view, the layout of subviews within the view, and business logic into separate classes, all while presenting a single, monolithic interface to the user. The loss of this ability without writing tons of boilerplate is one of the things about Swift that makes me sad.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">The one thing I’d change is upgrading the partial forwarding synthesis to the original proposal, as that’s a rather important feature IMO.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div></div></blockquote><div><br class=""></div><div>Thanks Charles. &nbsp;Do you disagree with the reasons I decided not to include partial forwarding in the initial proposal (it is discussed in alternatives considered)?</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Charles</div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class="">On Dec 29, 2015, at 10:37 AM, Matthew Johnson 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="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">I have completed a first draft of a proposal to introduce automatic protocol forwarding. &nbsp;I’m looking forward to feedback from everyone!<div class=""><div class=""><h1 id="automaticprotocolforwarding" class="" style="font-size: 37px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Automatic protocol forwarding</h1><ul class="" style="margin-top: 21px; margin-bottom: 21px; padding-left: 1.5em; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px;"><li class="" style="font-size: 17px;">Proposal:&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/NNNN-automatic-protocol-forwarding.md" class="" style="color: rgb(13, 110, 161); text-decoration: none; -webkit-transition: color 0.2s ease-in-out; transition: color 0.2s ease-in-out;">SE-NNNN</a></li><li class="" style="font-size: 17px;">Author(s):&nbsp;<a href="https://github.com/anandabits" class="" style="color: rgb(13, 110, 161); text-decoration: none; -webkit-transition: color 0.2s ease-in-out; transition: color 0.2s ease-in-out;">Matthew Johnson</a></li><li class="" style="font-size: 17px;">Status:&nbsp;<strong class="" style="line-height: 1;">Review</strong></li><li class="" style="font-size: 17px;">Review manager: TBD</li></ul><h2 id="introduction" class="" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Introduction</h2><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">Automatic protocol forwarding introduces the ability to use delegation without the need write forwarding member implementations manually.&nbsp;</p><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">A preliminary mailing list thread on this topic had the subject&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/000931.html" class="" style="color: rgb(13, 110, 161); text-decoration: none; -webkit-transition: color 0.2s ease-in-out; transition: color 0.2s ease-in-out;">protocol based invocation forwarding</a></p><h2 id="motivation" class="" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Motivation</h2><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">Delegation is a robust, composition oriented design technique that keeps interface and implementation inheritance separate. The primary drawback to this technique is that it requires a lot of manual boilerplate to forward implemenation to the implementing member. This proposal eliminates the need to write such boilerplate manually, thus making delegation-based designs much more convenient and attractive.</p><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">This proposal may also serve as the foundation for a future enhancement allowing a very concise “newtype” declaration.</p><h2 id="proposedsolution" class="" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Proposed solution</h2><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">I propose introducing a&nbsp;<code class="" style="line-height: 1;">forward</code>&nbsp;declaration be allowed within a type declaration or type extension. The&nbsp;<code class="" style="line-height: 1;">forward</code>&nbsp;declaration will cause the compiler to synthesize implementations of the members required by the forwarded protocols. The synthesized implementations will simply forward the method call to the specified member.</p><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">The basic declaration looks like this:</p><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;">forward <span class="hljs-type">Protocol</span>, <span class="hljs-type">OtherProtocol</span> to memberIdentifier</code></pre><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">The first clause contains a list of protocols to forward.&nbsp;</p><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">The second clause specifies the identifier of the property to which the protocol members will be forwarded. Any visible property that implements the members required by the protocol is eligible for forwarding. It does not matter whether it is stored, computed, lazy, etc.</p><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">It is also possible to include an access control declaration modifier to specify the visibility of the synthesized members.</p><h3 id="selfparameters" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Self parameters</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">When a protocol member includes a&nbsp;<code class="" style="line-height: 1;">Self</code>&nbsp;parameter forwarding implementations must accept the&nbsp;<strong class="" style="line-height: 1;">forwarding</strong>&nbsp;type but supply an argument of the&nbsp;<strong class="" style="line-height: 1;">forwardee</strong>&nbsp;type when making the forwarding call. The most straightforward way to do this is to simply use the same property getter that is used when forwarding. This is the proposed solution.</p><h3 id="selfreturntypes" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Self return types</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">When a protocol member includes a&nbsp;<code class="" style="line-height: 1;">Self</code>&nbsp;return type forwarding implementations must return the&nbsp;<strong class="" style="line-height: 1;">forwarding</strong>&nbsp;type. However, the&nbsp;<strong class="" style="line-height: 1;">forwardee</strong>&nbsp;implmentation will return a value of the&nbsp;<strong class="" style="line-height: 1;">forwardee</strong>&nbsp;type. This result must be used to produce a value of the&nbsp;<strong class="" style="line-height: 1;">forwarding</strong>&nbsp;type in some way.</p><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">The solution in this proposal is based on an ad-hoc overloading convention. A protocol-based solution would probably be desirable if it were possible, however it is not. This proposal supports forwarding to more than one member, possibly with different types. A protocol-based solution would require the&nbsp;<em class="" style="line-height: 1;">forwarding</em>&nbsp;type to conform to the “<code class="" style="line-height: 1;">Self</code>&nbsp;return value conversion” protocol once for each forwardee type.</p><h4 id="staticmembers" class="" style="color: rgb(17, 17, 17); font-size: 20px; line-height: 21px; margin-top: 21px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Static members</h4><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">When a&nbsp;<strong class="" style="line-height: 1;">forwardee</strong>&nbsp;value is returned from a static member an initializer will be used to produce a final return value. The initializer must be visible at the source location of the&nbsp;<code class="" style="line-height: 1;">forward</code>&nbsp;declaration and must look like this:</p><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Forwarder</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">let</span> forwardee: <span class="hljs-type">Forwardee</span>
    forward <span class="hljs-type">P</span> to forwardee
    <span class="hljs-keyword" style="font-weight: bold;">init</span>(<span class="hljs-number" style="color: rgb(0, 153, 153);">_</span> forwardeeReturnValue: <span class="hljs-type">Forwardee</span>) { <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">//... }</span>
}
</code></pre><h4 id="instancemembers" class="" style="color: rgb(17, 17, 17); font-size: 20px; line-height: 21px; margin-top: 21px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Instance members</h4><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">When a&nbsp;<strong class="" style="line-height: 1;">forwardee</strong>&nbsp;value is returned from an instance member an instance method will be used to transform the return value into a value of the correct type. An instance method is necessary in order to allow the&nbsp;<em class="" style="line-height: 1;">forwarding</em>&nbsp;type to access the state of the instance upon which the method was called when performing the transformation.</p><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">If the instance method is not implemented the initializer used for static members will be used instead.</p><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">The transformation has the form:</p><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Forwarder</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">let</span> forwardee: <span class="hljs-type">Forwardee</span>
    forward <span class="hljs-type">P</span> to forwardee
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">transformedForwardingReturnValue</span><span class="hljs-params">(forwardeeReturnValue: Forwardee)</span></span> -&gt; <span class="hljs-type">Forwarder</span> { <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">//... }</span>
}
</code></pre><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">NOTE: This method should have a better name. Suggestions are appreciated!</p><h3 id="examples" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Examples</h3><h4 id="basicexample" class="" style="color: rgb(17, 17, 17); font-size: 20px; line-height: 21px; margin-top: 21px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Basic example</h4><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">NOTE:&nbsp;<code class="" style="line-height: 1;">Forwardee</code>&nbsp;does not actually conform to&nbsp;<code class="" style="line-height: 1;">P</code>&nbsp;itself. Conformance is not required to synthesize the forwarding member implementations. It is only required that members necessary for forwarding exist. This is particularly important to the second example.</p><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">typealias</span> <span class="hljs-type">TA</span>
    <span class="hljs-keyword" style="font-weight: bold;">var</span> i: <span class="hljs-type">Int</span>
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span>
}

<span class="hljs-keyword" style="font-weight: bold;">private</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Forwardee</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">typealias</span> <span class="hljs-type">TA</span> = <span class="hljs-type">String</span>
    <span class="hljs-keyword" style="font-weight: bold;">var</span> i: <span class="hljs-type">Int</span> = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span> { <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-literal">true</span> }
}

<span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Forwarder</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">private</span> <span class="hljs-keyword" style="font-weight: bold;">let</span> forwardee: <span class="hljs-type">Forwardee</span>
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">extension</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Forwarder</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{        
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user declares</span>
    <span class="hljs-keyword" style="font-weight: bold;">public</span> forward <span class="hljs-type">P</span> to forwardee
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes</span>
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// TA must be synthesized as it cannot be inferred for this protocol</span>
    <span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-keyword" style="font-weight: bold;">typealias</span> <span class="hljs-type">TA</span> = <span class="hljs-type">String</span> 
    <span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-keyword" style="font-weight: bold;">var</span> i: <span class="hljs-type">Int</span> {
        <span class="hljs-keyword" style="font-weight: bold;">get</span> { <span class="hljs-keyword" style="font-weight: bold;">return</span> forwardee.i }
        <span class="hljs-keyword" style="font-weight: bold;">set</span> { forwardee.i = newValue }
    }
    <span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span> { 
        <span class="hljs-keyword" style="font-weight: bold;">return</span> forwardee.foo() 
    }
}</code></pre><h4 id="existentialforwardee" class="" style="color: rgb(17, 17, 17); font-size: 20px; line-height: 21px; margin-top: 21px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Existential forwardee</h4><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">NOTE: Existentials of type&nbsp;<code class="" style="line-height: 1;">P</code>&nbsp;do not actually conform to&nbsp;<code class="" style="line-height: 1;">P</code>&nbsp;itself. Conformance is not required to synthesize the forwarding member implementations. It is only required that members necessary for forwarding exist.</p><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span>
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">S</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">private</span> <span class="hljs-keyword" style="font-weight: bold;">let</span> p: <span class="hljs-type">P</span>
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user declares:</span>
    forward <span class="hljs-type">P</span> to p
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> p.foo()
    }
}</code></pre><h4 id="selfparameters2" class="" style="color: rgb(17, 17, 17); font-size: 20px; line-height: 21px; margin-top: 21px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Self parameters</h4><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(value: <span class="hljs-keyword" style="font-weight: bold;">Self</span>)</span></span> -&gt; <span class="hljs-type">Bool</span>
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">extension</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Int</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(value: Int)</span></span> -&gt; <span class="hljs-type">Bool</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> value != <span class="hljs-keyword" style="font-weight: bold;">self</span>
    }
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">S</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">private</span> <span class="hljs-keyword" style="font-weight: bold;">let</span> i: <span class="hljs-type">Int</span>
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user declares:</span>
    forward <span class="hljs-type">P</span> to i
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(value: S)</span></span> -&gt; <span class="hljs-type">Bool</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> i.foo(value.i)
    }
}</code></pre><h4 id="selfreturntypes2" class="" style="color: rgb(17, 17, 17); font-size: 20px; line-height: 21px; margin-top: 21px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Self return types</h4><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">Using the instance method:</p><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Self</span>
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">extension</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Int</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Int</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-keyword" style="font-weight: bold;">self</span> + <span class="hljs-number" style="color: rgb(0, 153, 153);">1</span>
    }
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">S</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">private</span> <span class="hljs-keyword" style="font-weight: bold;">let</span> i: <span class="hljs-type">Int</span>
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">transformedForwardingReturnValue</span><span class="hljs-params">(forwardeeReturnValue: Int)</span></span> -&gt; <span class="hljs-type">S</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-type">S</span>(i: forwardeeReturnValue)
    }
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user declares:</span>
    forward <span class="hljs-type">P</span> to i
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">S</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-keyword" style="font-weight: bold;">self</span>.transformedForwardingReturnValue(i.foo())
    }
}</code></pre><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">Using the initializer:</p><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Self</span>
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">extension</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Int</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Int</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-keyword" style="font-weight: bold;">self</span> + <span class="hljs-number" style="color: rgb(0, 153, 153);">1</span>
    }
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">S</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">private</span> <span class="hljs-keyword" style="font-weight: bold;">let</span> i: <span class="hljs-type">Int</span>
    <span class="hljs-keyword" style="font-weight: bold;">init</span>(<span class="hljs-number" style="color: rgb(0, 153, 153);">_</span> value: <span class="hljs-type">Int</span>) {
        i = value
    }
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user declares:</span>
    forward <span class="hljs-type">P</span> to i
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">S</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-type">S</span>(i.foo())
    }
}</code></pre><h4 id="forwardingmultipleprotocols" class="" style="color: rgb(17, 17, 17); font-size: 20px; line-height: 21px; margin-top: 21px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Forwarding multiple protocols</h4><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span>
}
<span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Q</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span>
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">extension</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Int</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span>, <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Q</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-literal">true</span>
    }
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-literal">false</span>
    }
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">S</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span>, <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Q</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">private</span> <span class="hljs-keyword" style="font-weight: bold;">let</span> i: <span class="hljs-type">Int</span>
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user declares:</span>
    forward <span class="hljs-type">P</span>, <span class="hljs-type">Q</span> to i
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> i.foo()
    }
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> i.bar()
    }
}</code></pre><h4 id="forwardingtomultiplemembers" class="" style="color: rgb(17, 17, 17); font-size: 20px; line-height: 21px; margin-top: 21px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Forwarding to multiple members</h4><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span>
}
<span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Q</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span>
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">extension</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Int</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-literal">true</span>
    }
}
<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">extension</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Double</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Q</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-literal">false</span>
    }
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">S</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span>, <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Q</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">private</span> <span class="hljs-keyword" style="font-weight: bold;">let</span> i: <span class="hljs-type">Int</span>
    <span class="hljs-keyword" style="font-weight: bold;">private</span> <span class="hljs-keyword" style="font-weight: bold;">let</span> d: <span class="hljs-type">Double</span>
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user declares:</span>
    forward <span class="hljs-type">P</span> to i
    forward <span class="hljs-type">Q</span> to d
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> i.foo()
    }
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Bool</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> d.bar()
    }
}</code></pre><h4 id="non-finalclass" class="" style="color: rgb(17, 17, 17); font-size: 20px; line-height: 21px; margin-top: 21px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Non-final class</h4><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">NOTE:&nbsp;<code class="" style="line-height: 1;">C</code>&nbsp;cannot declare conformance to the protocol due to the&nbsp;<code class="" style="line-height: 1;">Self</code>&nbsp;return value requirement. However, the compiler still synthesizes the forwarding methods and allows them to be used directly by users of&nbsp;<code class="" style="line-height: 1;">C</code>.</p><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-keyword" style="font-weight: bold;">public</span> <span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Self</span>
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">extension</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Int</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Int</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-keyword" style="font-weight: bold;">self</span> + <span class="hljs-number" style="color: rgb(0, 153, 153);">1</span>
    }
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// C does not and cannot declare conformance to P</span>
<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">class</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">C</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">private</span> <span class="hljs-keyword" style="font-weight: bold;">let</span> i: <span class="hljs-type">Int</span>
    <span class="hljs-keyword" style="font-weight: bold;">init</span>(<span class="hljs-number" style="color: rgb(0, 153, 153);">_</span> value: <span class="hljs-type">Int</span>) {
        i = value
    }
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user declares:</span>
    forward <span class="hljs-type">P</span> to i
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">C</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-type">C</span>(i.foo())
    }
}</code></pre><h2 id="detaileddesign" class="" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Detailed design</h2><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">TODO: grammar modification to add the&nbsp;<code class="" style="line-height: 1;">forward</code>&nbsp;declaration</p><ol class="" style="margin-top: 21px; margin-bottom: 21px; padding-left: 1.5em; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px;"><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">Automatic forwarding only synthesizes member implementations. It does not automatically conform the forwarding type to the protocol(s) that are forwarded. If actual conformance is desired (as it usually will be) it must be explicitly stated.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">The forwardee type need not actually conform to the protocol forwarded to it. It only needs to implement the members the forwarder must access in the synthesized forwarding methods. This is particularly important as long as protocol existentials do not conform to the protocol itself.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">While it will not be possible to conform non-final classes to protocols containing a&nbsp;<code class="" style="line-height: 1;">Self</code>&nbsp;return type forwarding should still be allowed. The synthesized methods will have a return type of the non-final class which in which the forwarding declaration occured. The synthesized methods may still be useful in cases where actual protocol conformance is not necessary.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">All synthesized members recieve access control modifiers matching the access control modifier applied to the&nbsp;<code class="" style="line-height: 1;">forward</code>&nbsp;declaration.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">TODO: How should other annotations on the forwardee implementations of forwarded members (such as @warn_unused_result) be handled?&nbsp;</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">It is possible that the member implementations synthesized by forwarding will conflict with existing members or with each other (when forwarding more than one protocol). All such conflicts, with one exception, should produce a compiler error at the site of the forwarding declaration which resulted in conflicting members.<br class="">One specific case that&nbsp;<strong class="" style="line-height: 1;">should not</strong>&nbsp;be considered a conflict is when forwarding more than one protocol with&nbsp;<strong class="" style="line-height: 1;">identical</strong>&nbsp;member declarations to the&nbsp;<strong class="" style="line-height: 1;">same</strong>&nbsp;member of the forwarding type. In this case the synthesized implementation required to forward all of the protocols is identical. The compiler&nbsp;<strong class="" style="line-height: 1;">should not</strong>&nbsp;synthesize multiple copies of the implementation and then report a redeclaration error.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">It is likely that any attempt to forward different protocols with&nbsp;<code class="" style="line-height: 1;">Self</code>&nbsp;return types to more than one member of the same type will result in sensible behavior. This should probable be a compiler error. For example:</div></li></ol><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Self</span>
}
<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Q</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Self</span>
}

<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Forwarder</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span>, <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Q</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">let</span> d1: <span class="hljs-type">Double</span>
    <span class="hljs-keyword" style="font-weight: bold;">let</span> d2: <span class="hljs-type">Double</span>
    
    forward <span class="hljs-type">P</span> to d1
    forward <span class="hljs-type">Q</span> to d2

    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">transformedForwardingReturnValue</span><span class="hljs-params">(<span class="hljs-number" style="color: rgb(0, 153, 153);">_</span> forwardeeReturnValue: Double)</span></span> -&gt; <span class="hljs-type">Forwarder</span> { 
        <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// What do we do here?  </span>
        <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// We don't know if the return value resulted from forwarding foo to d1 or bar to d2.</span>
        <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// It is unlikely that the same behavior is correct in both cases.</span>
    }
}</code></pre><h2 id="impactonexistingcode" class="" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Impact on existing code</h2><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">This is a strictly additive change. It has no impact on existing code.</p><h2 id="futureenhancements" class="" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Future enhancements</h2><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">In the spirit of incremental change, this proposal focuses on core functionality. Several enhancements to the core functionality are possible and are likely to be explored in the future.</p><h3 id="partialforwardingsynthesis" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Partial forwarding synthesis</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">The current proposal makes automatic forwarding an “all or nothing” feature. In cases where you want to forward most of the implementation of a set of members but would need to “override” one or more specific members the current proposal will not help. You will still be required to forward the entire protocol manually. Attempting to implement some specific members manually will result in a redeclaration error.</p><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">This proposal does not allow partial forwarding synthesis in order to focus on the basic forwarding mechanism and allow us to gain some experience with that first, before considering the best way to make partial forwarding possible without introducing unintended potential for error. One example of a consideration that may apply is whether or not&nbsp;<em class="" style="line-height: 1;">forwardee</em>&nbsp;types should be able to mark members as “final for forwarding” in some way that prevents them from being “overriden” by a forwarder.</p><h3 id="newtype" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Newtype</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">While the current proposal provides the basic behavior desired for&nbsp;<code class="" style="line-height: 1;">newtype</code>, it is not as concise as it could be. Adding syntactic sugar to make this common case more concise would be straightforward:</p><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user declares</span>
newtype <span class="hljs-type">Weight</span> = <span class="hljs-type">Double</span> forwarding <span class="hljs-type">P</span>, <span class="hljs-type">Q</span>

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes</span>
<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">struct</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Weight</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">P</span>, <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Q</span> </span>{
    <span class="hljs-keyword" style="font-weight: bold;">var</span> value: <span class="hljs-type">Double</span>
    forward <span class="hljs-type">P</span>, <span class="hljs-type">Q</span> to value
    <span class="hljs-keyword" style="font-weight: bold;">init</span>(<span class="hljs-number" style="color: rgb(0, 153, 153);">_</span> value: <span class="hljs-type">Double</span>) { <span class="hljs-keyword" style="font-weight: bold;">self</span>.value = value }
}</code></pre><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">However, there are&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151228/004735.html" class="" style="color: rgb(13, 110, 161); text-decoration: none; -webkit-transition: color 0.2s ease-in-out; transition: color 0.2s ease-in-out;">additional nuances related to associated types</a>&nbsp;that should be considered and addressed by a&nbsp;<code class="" style="line-height: 1;">newtype</code>&nbsp;proposal.</p><h3 id="forwardingdeclarationinprotocolextensions" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Forwarding declaration in protocol extensions</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">It may be possible to allow the&nbsp;<code class="" style="line-height: 1;">forward</code>&nbsp;declaration in protocol extensions by forwarding to a required property of the protocol. This may have implementation complexities and other implications which would hold back the current proposal if it required the&nbsp;<code class="" style="line-height: 1;">forward</code>&nbsp;declaration to be allowed in protocol extensions.&nbsp;</p><h2 id="alternativesconsidered" class="" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Alternatives considered</h2><h3 id="specifyforwardingaspartofthememberdeclaration" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Specify forwarding as part of the member declaration</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">I originally thought it would make the most sense to specify forwarding alongside the forwardee member declaration. This proposal does not do so for the following reasons:</p><ol class="" style="margin-top: 21px; margin-bottom: 21px; padding-left: 1.5em; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px;"><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">We must be able to specify access control for the forwarded members that are synthesized. Introducing a forwarding declaration is the most clear way to allow this.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">It will sometimes be necessary to forward different protocols to the same forwardee with different access control levels. It would be very clunky to do this as part of the member declaration.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">It should be possible to synthesize forwarding retroactively as part of an extension. This would not be possible if forwarding had to be specified in the original member declaration.</div></li></ol><h3 id="requiretheforwardeetoconformtotheprotocolsforwardedtoit" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Require the forwardee to conform to the protocol(s) forwarded to it</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">There is not a compelling reason to require this. It is not necessary to synthesize and compile the forwarding methods and it would prevent the use of protocol existentials as the forwardee.</p><h3 id="automaticallyconformtheforwardingtypetotheforwardedprotocols" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Automatically conform the forwarding type to the forwarded protocol(s)</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">It may seem reasonable to automatically synthesize conformance to the protocol in addition to the member implementations. This proposal does not do so for the following reasons:</p><ol class="" style="margin-top: 21px; margin-bottom: 21px; padding-left: 1.5em; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px;"><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">Forwarding is considered an implementation detail that is not necessarily visible in the public interface of the type. The forwardee may be a private member of the type.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">Type authors may wish to control where the actual conformance is declared, especially if protocol conformances are allowed to have access control in the future.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">There&nbsp;<em class="" style="line-height: 1;">may</em>&nbsp;be use cases where it is desirable to have the forwarded members synthesized&nbsp;<em class="" style="line-height: 1;">without</em>&nbsp;actually conforming to the protocol. This is somewhat speculative, but there is not a compelling reason to disallow it.</div></li></ol><h3 id="allowforwardingofallprotocolsconformedtobytheforwardeewithoutexplicitlylistingthem" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Allow forwarding of all protocols conformed to by the forwardee without explicitly listing them</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">It may seem reasonable to have a&nbsp;<code class="" style="line-height: 1;">*</code>&nbsp;placeholder which will forward all visible protocol conformances of the forwardee type. This proposal does not include such a placeholder for the following reasons:</p><ol class="" style="margin-top: 21px; margin-bottom: 21px; padding-left: 1.5em; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px;"><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">A placeholder like this could lead to unintended operations being synthesized if additional conformances are declared in the future. The new conformances could even lead to conflicts during synthesis which cause the code to fail to compile. The potential for such breakage is not acceptable.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">A placeholder like this would not necessarily cause all desired forwarding methods to be synthesized. This would be the case when the members necessary to conform exist but actual conformance does not exist. This would be the case when the forwardee type is an existential. This could lead to programmer confusion.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">An explicit list of protocols to forward is not unduely burdensome. It is straightforward to declare a new protocol that inherits from a group of protocols which are commonly forwarded together and use the new protocol in the forwarding declaration.</div></li><li class="" style="font-size: 17px;"><div class="" style="word-wrap: break-word; margin: 0px; line-height: 1.3125em;">This is easily added as a future enhancement to the current proposal if we later decide it is necessary.</div></li></ol><h3 id="allowforwardingoftheentireinterfaceoftheforwardeetypenotjustspecificprotocols" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Allow forwarding of the entire interface of the forwardee type, not just specific protocols</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">It is impossible to synthesize forwarding of methods which contain the forwardee type as a parameter or return type that are not declared as part of a protocol interface in a correct and safe manner. This is because it may or may not be correct to promote the&nbsp;<strong class="" style="line-height: 1;">forwardee</strong>&nbsp;type in the signature to the&nbsp;<strong class="" style="line-height: 1;">forwarder</strong>.&nbsp;</p><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">As an example, consider the following extension to&nbsp;<code class="" style="line-height: 1;">Double</code>. Imagine trying to synthesize a forwarding method in a&nbsp;<code class="" style="line-height: 1;">Pixel</code>&nbsp;type that forwards to&nbsp;<code class="" style="line-height: 1;">Double</code>. Should the return type be&nbsp;<code class="" style="line-height: 1;">Pixel</code>&nbsp;or&nbsp;<code class="" style="line-height: 1;">Double</code>? It is impossible to tell for sure.</p><pre class="" style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);"><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">extension</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">Double</span> </span>{
    <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -&gt; <span class="hljs-type">Double</span> {
        <span class="hljs-keyword" style="font-weight: bold;">return</span> <span class="hljs-keyword" style="font-weight: bold;">self</span>
    }
}</code></pre><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">When the method is declared in a protocol it becomes obvious what the signature of the forwarding method must be. If the protocol declares the return type as&nbsp;<code class="" style="line-height: 1;">Self</code>, the forwarding method must have a return type of&nbsp;<code class="" style="line-height: 1;">Pixel</code>. If the protocol declares the return type as&nbsp;<code class="" style="line-height: 1;">Double</code>&nbsp;the forwarding method will continue to have a return type of&nbsp;<code class="" style="line-height: 1;">Double</code>.</p><h3 id="allowforwardingtooptionalmembers" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Allow forwarding to&nbsp;<code class="" style="line-height: 1;">Optional</code>&nbsp;members</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">It may seem like a good idea to allow synthesized forwarding to&nbsp;<code class="" style="line-height: 1;">Optional</code>&nbsp;members where a no-op results when the&nbsp;<code class="" style="line-height: 1;">Optional</code>&nbsp;is&nbsp;<code class="" style="line-height: 1;">nil</code>. There is no way to make this work in general as it would be impossible to forward any member requiring a return value. If use cases for forwarding to&nbsp;<code class="" style="line-height: 1;">Optional</code>members emerege that are restricted to protocols with no members requiring return values the automatic protocol forwarding feature could be enhanced in the future to support these use cases.</p><h3 id="allowforwardingthesameprotocolstomorethanonemember" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Allow forwarding the same protocol(s) to more than one member</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">As with forwarding to&nbsp;<code class="" style="line-height: 1;">Optional</code>&nbsp;members, forwarding the same protocol to more than one member is not possible in general. However it&nbsp;<em class="" style="line-height: 1;">is</em>&nbsp;possible in cases where no protocol members have a return value. If compelling use cases emerge to motivate automatic forwarding of such protocols to more than one member an enhancement could be proposed in the future.</p><h3 id="provideamechanismforforwardeestoknowabouttheforwarder" class="" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;">Provide a mechanism for forwardees to know about the forwarder</h3><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">Some types may be designed to be used as components that are always forwarded to by other types. Such types may wish to be able to communicate with the forwarding type in some way. This can be accomplished manually.&nbsp;</p><p class="" style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;">If general patterns emerge in practice it may be possible to add support for them to the language. However, it would be preliminary to consider support for such a feature until we have significant experience with the basic forwarding mechanism itself.</p></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=kND2tqgLiolwf1-2Bhgg7fFiaPS455NT9j3CATwJCX70-2BUbIlWiVEDSEMFGWxw4AOmVThzbGKzErDZa7D6zaRwRsXX1QtP44P7hUaN0pvqFROlHDVOORh2YLpHozWxm7fUP-2Bb2FcwDmC9uEVAd1aFGtxgeSVOdU5p8olZupw2KRxogXAUUsUqQNI4wvgv-2B5pBmIwlmuIm5olzNQ63wvmoshxdXhMzilFVl16zKwWTOvsA-3D" alt="" width="1" height="1" border="0" class="" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div></div></blockquote></div><br class=""></body></html>