<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 14, 2015, at 10:01 AM, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:</div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">struct</span> RequestBatch</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">var</span> requests: [<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Request</span>] &nbsp;<font color="#901000" class="">// Sadness. Despair. DOOOOM.</font></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span> cancelAll()</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">for</span> request <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">requests</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { request.<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">cancel</span>() }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div></div><div class=""><br class=""></div><div class="">The current Swift solution is either to ditch the type safety of ContentType, or split Request into two protocols. The latter makes the API hard to read, and may decouple related protocol requirements that don’t make sense independently.</div></div></div></blockquote><br class=""></div><div class="">IMO the fact that you created an a array of requests and wrote cancelAll above *demonstrates* that the cancel requirement makes sense independently from the others.</div></div></div></blockquote><br class=""></div><div>…and therein lies the danger of small examples trimmer from larger projects. In the actual project, I end up with a family of related behaviors where the “cancel / everything else” separation no longer makes sense.</div><div><br class=""></div><div>Here’s a little more context — still a super pared down toy example, but hopefully enough to demonstrate. What I want:</div><div><br class=""></div><div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class=""><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class=""><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">protocol</span> Resource</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">typealias</span> ContentType</div><p style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">var</span> allRequests: [<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Request</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">ContentType</span>&gt;] { <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">get</span> }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">var</span> latestData: <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">ContentType</span>? { <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">get</span> }</div><p style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;" class=""><span style="font-size: 10.5px;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-size: 10.5px; color: rgb(50, 62, 125);" class="">func</span><span style="font-size: 10.5px;" class=""> load() -&gt; </span><span style="font-size: 10.5px; color: rgb(88, 126, 168);" class="">Request</span><span style="font-size: 10.5px;" class="">&lt;</span><span style="font-size: 10.5px; color: rgb(88, 126, 168);" class="">ContentType</span><span style="font-size: 10.5px;" class="">&gt;</span></p><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;" class=""><br class=""></div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">protocol</span> Request</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">typealias</span> ContentType</div><p style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span> onSuccess(callback: <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">ContentType</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Void</span>)</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span> onFailure(callback: <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">ErrorType</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Void</span>)</div><p style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;" class=""><span style="font-size: 10.5px;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-size: 10.5px; color: rgb(50, 62, 125);" class="">func</span><span style="font-size: 10.5px;" class=""> cancel()</span></p><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;" class=""><br class=""></div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">struct</span>&nbsp;<span style="font-size: 10.5px;" class="">ResourceBatch</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">var</span> observedResources: [<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Resource</span>]</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">var</span> reloadsInProgress: <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Int</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">0</span></div><p style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span> reloadAll()</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">for</span> resource <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">observedResources</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">reloadsInProgress</span> += <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">1</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resource.<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">load</span>().<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">onSuccess</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">_</span> <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">reloadsInProgress</span> -= <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">1</span> }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class=""><span style="font-size: 10.5px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-size: 10.5px;" class="">}</span></div><p style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span> cancelAll()</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">for</span> resource <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">observedResources</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">for</span> request <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">in</span> resource.<span style="color: rgb(88, 126, 168); font-size: 10.5px;" class="">allRequests</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { request.cancel() }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;" class=""><br class=""></div></div></div></div></div>And here’s the nonsense I have to engage in to make this work with Swift as it stands:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">protocol</span> AnyResource</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">var</span> allRequests: [<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">AnyRequest</span>] { <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">get</span> }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color: rgb(50, 62, 125);" class="">var</span>&nbsp;anyLatestData:&nbsp;<span style="color: rgb(88, 126, 168);" class="">Any</span>? {&nbsp;<span style="color: rgb(50, 62, 125);" class="">get</span>&nbsp;}</div><p style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class=""><span style="font-size: 10.5px;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-size: 10.5px; color: rgb(50, 62, 125);" class="">func</span><span style="font-size: 10.5px;" class=""> load() -&gt; </span><span style="font-size: 10.5px; color: rgb(88, 126, 168);" class="">AnyRequest</span></p><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class=""><br class=""></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">protocol</span> Resource: <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">AnyResource</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">typealias</span> ContentType</div><p style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">var</span> allRequests: [<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">AnyRequest</span>] { <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">get</span> } &nbsp;// ← Still no way to make this typesafe</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">var</span> latestData: <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">ContentType</span>? { <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">get</span> }</div><p style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; color: rgb(88, 126, 168);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> load&lt;RequestType: </span>Request<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">where</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>RequestType<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span>ContentType<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> == </span>Self<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span>ContentType<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&gt;() -&gt; </span>RequestType</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class=""><br class=""></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">protocol</span> AnyRequest</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span> onSuccess(callback: <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Any</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Void</span>)</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span> onFailure(callback: <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">ErrorType</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Void</span>)</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span> cancel()</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class=""><br class=""></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">protocol</span> Request: <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">AnyRequest</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">typealias</span> ContentType</div><p style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span> onSuccess(callback: <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">ContentType</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Void</span>)</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class=""><br class=""></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">struct</span> ResourceBatch</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">var</span> observedResources: [<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">AnyResource</span>]</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">var</span> reloadsInProgress: <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Int</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">0</span></div><p style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">mutating</span> <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span> reloadAll()</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">for</span> resource <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">observedResources</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">reloadsInProgress</span> += <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">1</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resource.<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">load</span>().<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">onSuccess</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">_</span> <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">reloadsInProgress</span> -= <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">1</span> }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><p style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span> cancelAll()</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">for</span> resource <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">observedResources</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">for</span> request <span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">in</span> resource.<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">allRequests</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { request.<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">cancel</span>() }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div></div><div class=""><br class=""></div><div class="">Still just a sketch, but already the problems abound.</div><div class=""><br class=""></div><div class="">This Resource / AnyResource and Request / AnyRequest distinction makes no useful sense to the user of this library; it’s just there to satisfy Swift’s type system. “Resource whose ContentType is known at compile time” and “Resource whose ContentType is unknown at compile time” are still the same construct, conceptually and semantically, just with varying degrees of type information. They should not be two types.</div><div class=""><br class=""></div><div class="">I tried playing out this approach in Siesta, and it lead to a combinatorial explosion of duplicated methods, and numerous type inference problems related to the collision of methods that differed only by Any vs. ContentType. I wasn’t willing to inflict the resulting API on my users.</div><div class=""><br class=""></div><div class="">Maybe I’m missing something big. David, you certainly know Swift better than I do. If there’s a better way to do this, I would love to hear about it!</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Paul</div><div class=""><br class=""></div></body></html>