<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="">Hi,<div class=""><br class=""></div><div class="">I am having trouble with the below mentioned code.</div><div class=""><br class=""></div><div class="">It crashes in <font color="#0433ff" class="">Xcode 9.0 beta 3 (9M174d) </font>but doesn’t crash in <span style="color: rgb(4, 51, 255);" class="">Xcode 8.3.3 (8E3004b)</span></div><div class=""><br class=""></div><div class=""><b class="">Observations in Xcode 9:</b></div><div class="">- When <font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">Car</span></font> is changed into a <font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">struct</span></font> and <font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">test</span></font> is made to be <font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">mutating</span></font>, it doesn’t crash</div><div class=""><div class="">- When <span style="color: rgb(4, 51, 255); font-family: Menlo; font-size: 11px;" class="">Helper</span> is changed to <font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">class</span></font>, it doesn’t crash</div></div><div class="">- In <font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">Helper</span></font>, when <font color="#0433ff" face="Menlo" style="font-size: 11px;" class="">doSomething</font> is changed to be <font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">non-mutating</span></font>, it doesn’t crash</div><div class=""><br class=""></div><div class=""><b class="">Questions:</b></div><div class="">- Is there a bug in my code which is being detected in <font color="#0433ff" class="">Xcode 9</font> ? If so could you please explain and suggest an alternate approach / fix ?</div><div class="">- Is this occurring because <span style="color: rgb(4, 51, 255); font-family: Menlo; font-size: 11px;" class="">class</span> doesn’t have the concept of mutating but <font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">struct</span></font> does and passing one’s function into the other causes this ?</div><div class=""><br class=""></div><div class=""><b class="">Code:</b></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">struct</span> Helper {</div><p style="margin: 0px; line-height: normal; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">var</span> v1 = <span style="color: #272ad8" class="">10</span></div><p style="margin: 0px; line-height: normal; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">mutating</span> <span style="color: #ba2da2" class="">func</span> doSomething(f1: () -> ()) {</div><div style="margin: 0px; line-height: normal;" class=""> f1()</div><div style="margin: 0px; line-height: normal;" class=""> }</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">class</span> Car {</div><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">var</span> helper = <span style="color: #4f8187" class="">Helper</span>()</div><p style="margin: 0px; line-height: normal; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">func</span> test() {</div><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #4f8187" class="">helper</span>.<span style="color: #31595d" class="">doSomething</span>(f1: <span style="color: #31595d" class="">f1</span>)</div><div style="margin: 0px; line-height: normal;" class=""> }</div><p style="margin: 0px; line-height: normal; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">func</span> f1() {</div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="color: #000000" class=""> </span><span style="color: #ba2da2" class="">_</span><span style="color: #000000" class=""> = </span><span style="color: #4f8187" class="">helper</span><span style="color: #000000" class="">.</span><span style="color: #4f8187" class="">v1</span><span style="color: #000000" class=""> </span>//Crash - Simultaneous accesses to <memory address>, but modification requires exclusive access.</div><div style="margin: 0px; line-height: normal;" class=""> }</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="color: rgb(186, 45, 162);" class="">var</span> car = <span style="color: #4f8187" class="">Car</span>()</div><div style="margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""><span style="color: #4f8187" class="">car</span><span style="color: #000000" class="">.</span>test<span style="color: #000000" class="">()</span></div></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><b class="">Crash:</b></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Simultaneous accesses to <memory address1>, but modification requires exclusive access.</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Previous access (a modification) started at SimultaneousAccess`Car.test() + 65 (<memory address2>).</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class=""><br class=""></b></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="font-family: Helvetica; font-size: 12px;" class=""><b class="">Testing:</b></div><div style="font-family: Helvetica; font-size: 12px;" class="">- Tested by creating <font color="#0433ff" class="">macOS command line application</font> and <font color="#0433ff" class="">iOS application (Simulator)</font></div><div style="font-family: Helvetica; font-size: 12px;" class=""><font color="#0433ff" class=""><br class=""></font></div></div><div style="margin: 0px; line-height: normal;" class="">Thanks and regards,</div><div style="margin: 0px; line-height: normal;" class="">Muthu</div></body></html>