<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">Hi Swift community,
<div><br /></div>
<div>I was wondering if we have considered adding support for providing Xcode automatic fix-it’s for closures being returned from a function.</div>
<div><br /></div>
<div>For example, here is an incorrect version of a function that requires two `@escaping` keywords to be inserted.</div>
<div><br /></div>
<div>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2">func</span> <span style="font-variant-ligatures: no-common-ligatures">mapping &lt;A, B, C&gt; (f:</span> <span style="font-variant-ligatures: no-common-ligatures">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">A</span><span style="font-variant-ligatures: no-common-ligatures">) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">B</span><span style="font-variant-ligatures: no-common-ligatures">)) -&gt;</span> <span style="font-variant-ligatures: no-common-ligatures">((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">C</span><span style="font-variant-ligatures: no-common-ligatures">,</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">B</span><span style="font-variant-ligatures: no-common-ligatures">) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">C</span><span style="font-variant-ligatures: no-common-ligatures">)) -&gt; ((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">C</span><span style="font-variant-ligatures: no-common-ligatures">,</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">A</span><span style="font-variant-ligatures: no-common-ligatures">) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">C</span><span style="font-variant-ligatures: no-common-ligatures">))</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures"><br /></span></p>
</div>
<div>Despite the complexity, the compiler manages to catch two errors.</div>
<div><br /></div>
<div>1. Closure use of non-escaping parameter `f` may allow it to escape</div>
<div> a. Automatic Fix-it by doing `f: @escaping (A) - &gt; (B)`<br /></div>
<div><br /></div>
<div>2. Closure use of non-escaping parameter `reducer` may allow it to escape</div>
<div> b. No Fix-it provided &lt;————&#160;<br /></div>
<div><br /></div>
<div>As you see above, the two places where a compile-time error occurred had the same exact problem; they both needed a `@escaping`. However, while the function parameter was offered an automatic fix-it, the nested closure being returned was not.</div>
<div><br /></div>
<div>
<div>Here’s the correct version of the function.</div>
<div><br /></div>
<div>
<div>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2">func</span> <span style="font-variant-ligatures: no-common-ligatures">mapping &lt;A, B, C&gt; (f:</span> <span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2">@escaping</span> <span style="font-variant-ligatures: no-common-ligatures">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">A</span><span style="font-variant-ligatures: no-common-ligatures">) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">B</span><span style="font-variant-ligatures: no-common-ligatures">)) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2">@escaping</span> <span style="font-variant-ligatures: no-common-ligatures">((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">C</span><span style="font-variant-ligatures: no-common-ligatures">,</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">B</span><span style="font-variant-ligatures: no-common-ligatures">) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">C</span><span style="font-variant-ligatures: no-common-ligatures">))) -&gt; ((</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">C</span><span style="font-variant-ligatures: no-common-ligatures">,</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">A</span><span style="font-variant-ligatures: no-common-ligatures">) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187">C</span><span style="font-variant-ligatures: no-common-ligatures">)) {</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">&#160; &#160;</span> <span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2">return</span> <span style="font-variant-ligatures: no-common-ligatures">{ reducer</span> <span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2">in</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">&#160; &#160; &#160; &#160;</span> <span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2">return</span> <span style="font-variant-ligatures: no-common-ligatures">{ accum, input</span> <span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2">in</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">&#160; &#160; &#160; &#160; &#160; &#160; reducer(accum, f(input))</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">&#160; &#160; &#160; &#160; }</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">&#160; &#160; }</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures">}</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures"><br /></span></p>
</div>
</div>
</div>
<div>I know this is a small feature for a very specific use case but I think it could help make Xcode a little smarter :D&#160;</div>
<div>Thanks for reading!</div>
<div>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><br /></p>
</div>
<div><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;"><br /></span></div>
<div><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;"><br /></span></div>
</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br /></div>
</body>
</html>