<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">+1 I can’t wait for Swift 3 anymore. This ability would be great.</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Additionally what do you think about something like this?</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">protocol DelegatableType {</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">&nbsp; &nbsp; &nbsp;protocol Delegate: class // enforced you to create a nested protocol</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">&nbsp; &nbsp; &nbsp;weak var delegate: Delegate? // or Self.Delegate?</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">}&nbsp;</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">class A: DelegatableType {</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">&nbsp; &nbsp; protocol Delegate { /* create something fancy */ }</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">&nbsp; &nbsp; var delegate: Delegate? // or A.Delegate? but I tend to just writing Delegate?</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">}</div> <br> <div id="bloop_sign_1462519294483418112" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">--&nbsp;<br>Adrian Zubarev<br>Sent with Airmail</div></div> <br><p class="airmail_on">Am 29. April 2016 bei 09:56:55, Krishna Kumar via swift-evolution (<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div></div><div>




<title></title>


Hey Brad
<div class=""><br class=""></div>
<div class="">+1 I think this will make delegate controller pattern
a lot more clean and readable.</div>
<div class=""><br class=""></div>
<div class="">I was thinking about other areas where this can be
useful, and I thought it will be great for property injection from
parent controller to children.</div>
<div class=""><br class=""></div>
<div class="">
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div class="">
<div class="">
<div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">
<div class="" style="margin: 0px; line-height: normal;">
<div style="margin: 0px; font-size: 11px; line-height: normal;" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> <span style="font-variant-ligatures: no-common-ligatures" class="">ParentController{</span></span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span> <span style="font-variant-ligatures: no-common-ligatures" class="">Injection:</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span><span style="font-variant-ligatures: no-common-ligatures" class="">{</span></div>
<p style="margin: 0px; font-size: 11px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p>
<div style="margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">override</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> <span style="font-variant-ligatures: no-common-ligatures" class="">prepareForSegue(segue:</span> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UIStoryboardSegue</span><span style="font-variant-ligatures: no-common-ligatures" class="">,
sender:</span> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">AnyObject</span><span style="font-variant-ligatures: no-common-ligatures" class="">?){</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp;</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures" class="">childVC =
segue.destinationViewController</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">as</span><span style="font-variant-ligatures: no-common-ligatures" class="">?
Injection</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; ...</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; min-height: 13px;" class=""><br class=""></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> <span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">ChildController:</span> <span style="font-variant-ligatures: no-common-ligatures" class="">ParentController</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">Injection</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">{</span></div>
<p style="margin: 0px; font-size: 11px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p>
<div style="margin: 0px; font-size: 11px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal;" class=""><br class=""></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="">
<table class="js-file-line-container highlight tab-size" data-tab-size="8" style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; color: rgb(51, 51, 51); font-family: Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 13px;">
</table>
<div class="">
<table class="js-file-line-container highlight tab-size" data-tab-size="8" style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; color: rgb(51, 51, 51); font-family: Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 13px;">
<tbody style="box-sizing: border-box;" class="">
<tr style="box-sizing: border-box;" class="">
<td id="file-nestedprotocol-swift-L5" class="blob-num js-line-number" data-line-number="5" style="box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 18px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;">
</td>
</tr>
</tbody>
</table>
<br class=""></div>
</div>
<div class="">Does this make sense?</div>
<div class=""><br class=""></div>
<div class="">-Krishna</div>
<div class=""><br class=""></div>
<div class="">
<div>
<blockquote type="cite" class="">
<div class="">On Apr 28, 2016, at 10:45 PM, Brad Hilton 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 style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Type nesting allows some convenient and straightforward
semantics that we see inside the Swift standard library such as
views on String like String.CharacterView,
String.UnicodeScalarView, etc. However a protocol cannot be nested
in a type and gives a non-obvious error that the “Declaration is
only valid at file scope.” Just as other nested types allow proper
contextual scoping, a nested protocol could make a lot sense for a
number of patterns. For example, there are many “Delegate”
protocols throughout the Cocoa frameworks. Here’s a
controller/delegate pattern before and after type nesting:
<div class="">
<div class=""><br class=""></div>
<div class="">
<div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">
<div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// Without type nesting</span></div>
<div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span> <span style="font-variant-ligatures: no-common-ligatures" class="">MyControllerDelegate :</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> <span style="font-variant-ligatures: no-common-ligatures" class="">{</span></div>
<div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> <span style="font-variant-ligatures: no-common-ligatures" class="">MyController
{</span></div>
<div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div>
<div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">weak</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> <span style="font-variant-ligatures: no-common-ligatures;" class="">delegate:</span> <span style="font-variant-ligatures: no-common-ligatures" class="">MyControllerDelegate</span><span style="font-variant-ligatures: no-common-ligatures;" class="">?</span></div>
<div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div>
<div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// With type nesting</span></div>
<div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> <span style="font-variant-ligatures: no-common-ligatures" class="">MyController
{</span></div>
<div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">weak</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> <span style="font-variant-ligatures: no-common-ligatures" class="">delegate:</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Delegate</span><span style="font-variant-ligatures: no-common-ligatures" class="">?</span></div>
<div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span> <span style="font-variant-ligatures: no-common-ligatures" class="">Delegate
:</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> <span style="font-variant-ligatures: no-common-ligatures" class="">{</span></div>
<div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div>
<div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; line-height: normal;" class=""><br class=""></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-family: Helvetica;" class="">Though the change is
mostly semantics, it does allow an explicit association between My
Controller and the Delegate instead of only a named association. It
also cleans up the module name space like other nested types and
makes associated protocols more discoverable in my
opinion.&nbsp;</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-family: Helvetica;" class=""><br class=""></span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-family: Helvetica;" class="">I’d love to hear
everyone’s thoughts.</span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-family: Helvetica;" class=""><br class=""></span></div>
<div style="margin: 0px; line-height: normal;" class="">
<span style="font-family: Helvetica;" class="">Brad
Hilton</span></div>
</div>
</div>
</div>
</div>
_______________________________________________<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>
</blockquote>
</div>
<br class=""></div>


_______________________________________________<br>swift-evolution mailing list<br>swift-evolution@swift.org<br>https://lists.swift.org/mailman/listinfo/swift-evolution<br></div></div></span></blockquote></body></html>