<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=""><div class="">I’d say that’s a bug! Mind filing it at <a href="https://bugs.swift.org" class="">https://bugs.swift.org</a> ?</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Jordan</div><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 4, 2017, at 12:41, Joe DeCapo via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi everyone,<br class=""><br class="">I'm not sure if there's a more appropriate place to ask this question, but I figured at the very least I could get pointed in the right direction. I've tried searching online and haven't been able to find anything addressing this.<br class=""><br class="">I was trying to use the `defer` statement in a Playground, and was surprised to find that it never prints anything in the preview pane on the side. I was expecting the evaluation of the code in the `defer` statement to show up in line with the statements, even though they're executed after the last line in the function. I made a very simple playground that modifies a global variable and prints the value in the `defer` statement, and when I print the global variable after calling my function it shows the correct updated value, so the code in the `defer` statement is getting run as expected. Here's my sample code with the Playground output in comments on the side:<br class=""><br class="">var x = 3<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>// 3<br class="">func doSomething() {<br class=""> print(1)<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>// "1\n"<br class=""> defer {<br class=""> x += 1<br class=""> print(x)<br class=""> }<br class=""> print(2)<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>// "2\n"<br class="">}<br class="">doSomething()<br class="">print(x)<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>// "4\n"<br class=""><br class="">I was expecting something like this:<br class=""><br class="">var x = 3<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>// 3<br class="">func doSomething() {<br class=""> print(1)<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>// "1\n"<br class=""> defer {<br class=""> x += 1<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>// 4<br class=""> print(x)<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>// "4\n"<br class=""> }<br class=""> print(2)<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>// "2\n"<br class="">}<br class="">doSomething()<br class="">print(x)<span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>// "4\n"<br class=""><br class="">Is there some deep reason why code in `defer` statements doesn't show anything in the preview pane in Playgrounds?<br class=""><br class="">-Joe<br class=""><br class=""><span id="cid:D1D3E162-7466-45F7-A8B0-E74E01D84915"><Defer.playground></span><br class=""><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></body></html>