<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="">What version of Swift are you using, and what exactly do you mean by 'Xcode cannot stop’? It seems like you might be using an older version of Swift, and have hit upon a compiler bug/performance issue that has since been fixed.</div><div class=""><br class=""></div>This code fails to compile for me in Swift 3.1:<div class=""><br class=""></div><div class=""><font face="Menlo" class="">'</font><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""><span style="color: rgb(186, 45, 162);" class="">let</span>&nbsp;dp</span><font face="Menlo" class="">'</font>&nbsp;should be '<span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">var</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">&nbsp;dp</span><font face="Menlo" class="">'</font><br class=""><div class=""><br class=""></div><div class="">With that fixed, the code takes ~10 seconds to compile (which is much longer than I would expect).&nbsp;</div><div class=""><br class=""></div><div class="">IIRC, the Swift compiler has a hard time with multidimensional arrays (maybe someone else could enlighten us on why that’s the case). Adapting your code to use a single array brings down the compile time to something much more reasonable, although the code becomes somewhat less intuitive:</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; color: rgb(186, 45, 162);" class="">class</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;Solution {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;rob(nums: [</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class="">]) -&gt;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">guard</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;nums.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">count</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&gt;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">else</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;{&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span></span><span style="color: rgb(186, 45, 162);" class="">let&nbsp;</span>stride:&nbsp;<span style="color: rgb(112, 61, 170);" class="">Int&nbsp;</span>=&nbsp;<span style="color: rgb(39, 42, 216);" class="">2</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="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;dp: [</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class="">] =&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Array</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">init</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(repeating:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, count: nums.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">count</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;*&nbsp;</span>stride)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;dp[</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">] =&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</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="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;dp[</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class="">] = nums[</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">for</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;i&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">in</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;..&lt; nums.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">count</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;base = i *&nbsp;</span>stride</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;prevBase = (i -&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) *&nbsp;</span>stride</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;dp[base] =&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);" class="">max</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(dp[prevBase], dp[prevBase +&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class="">])</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="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;dp[base +&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class="">] = dp[prevBase] + nums[i]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div></div></div><div class=""><br class=""></div><div class="">If you’re using an older version of Swift and are in a position to update - I’d suggest making the change. Otherwise I’d recommend avoiding multidimensional arrays (if possible).</div><div class=""><br class=""></div><div class="">Greg</div><div class=""><br class=""></div><div class=""><br class=""></div><div style=""><blockquote type="cite" class=""><div class="">On 5 Jun 2017, at 10:32 pm, Hbucius Smith via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:simsun,serif;font-size:small">Hi Swift-Users,</div><div class="gmail_default" style="font-family:simsun,serif;font-size:small"><br class=""></div><div class="gmail_default" style="font-family:simsun,serif;font-size:small">&nbsp; &nbsp; when I compiled the code, Xcode cannot stop, I do not know why. It is very strange. Can anyone help ? Here is the code. I am using Xcode 8.1</div><div class="gmail_default" style="font-family:simsun,serif;font-size:small"><br class=""></div><div class="gmail_default" style="font-family:simsun,serif;font-size:small"><p class="gmail-p1"><span class="gmail-s2">class</span><span class="gmail-s1"> Solution {</span><br class=""><span class="gmail-s1"></span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; </span><span class="gmail-s2">func</span><span class="gmail-s1"> rob(nums: [</span><span class="gmail-s3">Int</span><span class="gmail-s1">]) -&gt; </span><span class="gmail-s3">Int</span><span class="gmail-s1"> {</span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="gmail-s2">guard</span><span class="gmail-s1"> nums.count &gt; </span><span class="gmail-s4">0</span><span class="gmail-s1"> </span><span class="gmail-s2">else</span><span class="gmail-s1"> { </span><span class="gmail-s2">return</span><span class="gmail-s1"> </span><span class="gmail-s4">0</span><span class="gmail-s1"> }</span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="gmail-s2">let</span><span class="gmail-s1"> dp = Array.</span><span class="gmail-s2">init</span><span class="gmail-s1">(repeating: Array.</span><span class="gmail-s2">init</span><span class="gmail-s1">(repeating: </span><span class="gmail-s4">0</span><span class="gmail-s1">, count: nums.count),</span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; count: </span><span class="gmail-s4">2</span><span class="gmail-s1">)</span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; &nbsp; &nbsp; dp[</span><span class="gmail-s4">0</span><span class="gmail-s1">][</span><span class="gmail-s4">0</span><span class="gmail-s1">] = </span><span class="gmail-s4">0</span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; &nbsp; &nbsp; dp[</span><span class="gmail-s4">0</span><span class="gmail-s1">][</span><span class="gmail-s4">1</span><span class="gmail-s1">] = nums[</span><span class="gmail-s4">0</span><span class="gmail-s1">]</span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="gmail-s2">for</span><span class="gmail-s1"> i </span><span class="gmail-s2">in</span><span class="gmail-s1"> </span><span class="gmail-s4">1</span><span class="gmail-s1"> ..&lt; nums.count {</span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp[i][</span><span class="gmail-s4">0</span><span class="gmail-s1">] = max(dp[i - </span><span class="gmail-s4">1</span><span class="gmail-s1">][</span><span class="gmail-s4">0</span><span class="gmail-s1">], dp[i - </span><span class="gmail-s4">1</span><span class="gmail-s1">][</span><span class="gmail-s4">1</span><span class="gmail-s1">])</span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp[i][</span><span class="gmail-s4">1</span><span class="gmail-s1">] = dp[i - </span><span class="gmail-s4">1</span><span class="gmail-s1">][</span><span class="gmail-s4">0</span><span class="gmail-s1">] + nums[i]</span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="gmail-s2">return</span><span class="gmail-s1"> </span><span class="gmail-s4">0</span></p><p class="gmail-p2"><span class="gmail-s1">&nbsp; &nbsp; }</span></p><p class="gmail-p2"><span class="gmail-s1">}</span></p></div><div class="gmail_default" style="font-family:simsun,serif;font-size:small"><br class=""></div><div class="gmail_default" style="font-family:simsun,serif;font-size:small"><br class=""></div><br clear="all" class=""><div class=""><div class="gmail_signature"><i class=""><font face="georgia, serif" class="">best wishes for you&nbsp;</font></i></div></div>
</div>
_______________________________________________<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></blockquote></div><br class=""></body></html>