<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 8 Mar 2017, at 08:35, Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="bloop_markdown" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: 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; background-color: rgb(254, 254, 254);"><p style="margin: 15px 0px; -webkit-margin-before: 0px;" class="">The latter slightly confused me for a second and I had to double check. You’re saying that cases are not indented “because” they are part of the switch statement, but observers like<span class="Apple-converted-space"> </span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">willSet</code><span class="Apple-converted-space"> </span>and<span class="Apple-converted-space"> </span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal;" class="">didSet</code><span class="Apple-converted-space"> </span>are indented even if they are part of the property they are defined on. What’s the point I’m missing in this argument? (I’m precisely talking about the comparison between cases and observers, not about the indent elsewhere.)</p></div></div></blockquote></div><div>willSet and didSet have their own distinct scope; they execute independently, however a switch statement is effectively a single scope because of the ability to use fallthrough to visit later cases.</div><div><br class=""></div><div>To try and illustrate, consider the following switch statement:</div><div><br class=""></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>switch(foo) {</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case 1:</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>print("Case 1")</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case 2:</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>print("Case 2")</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>fallthrough</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>default:</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>print("Default")</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div><br class=""></div><div>If foo is equal to 2, the output will be both "Case 2" and "Default". Another way to think of this is in terms of how a switch statement actually executes, the above would become something resembling the following (using rough pseudo-code):</div><div><br class=""></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if (foo == 1) jump @case1</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>else if (foo == 2) jump @case2</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>else jump @default</font></div><div><font face="Monaco" class=""><br class=""></font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>@case1</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>print("Case 1")</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>jump @end</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>@case2</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>print("Case 2")</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// no jump because of fallthrough</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>@default</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>print("Default")</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>jump @end</font></div><div><font face="Monaco" class=""><br class=""></font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>@end</font></div><div><br class=""></div><div>I don't know if that helps clear it up, but while syntactically a switch statement's cases are grouped with the code that they trigger, this is just because it's easier to work with; in reality the entire content of the switch is one contiguous run of code that you jump into (and possibly out of) as determined by some form of test at the start. The ability for a case to fallthrough (no jump to the end) means that it's possible to execute multiple cases, unlike an if-statement where only one branch is ever executed.</div><div><br class=""></div><div>The lack of indentation is a good reminder that a case should be thought of more as a label, and that its condition is actually checked at the switch(foo) part of the construct.</div></body></html>