<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">Work around:</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="color:rgb(187,44,162)">do</span><span style=""> {</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> str = </span><span style="color:rgb(209,47,27)">&quot;abcdefg&quot;</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> str1 = str + </span><span style="color:rgb(209,47,27)">&quot;hijklmn&quot;</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(61,29,129)"><b><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(187,44,162)">let</span><span style="color:rgb(0,0,0)"> startIndex = str1.</span><span style="">rangeOfComposedCharacterSequenceAtIndex</span><span style="color:rgb(0,0,0)">(str.</span><span style="color:rgb(112,61,170)">startIndex</span><span style="color:rgb(0,0,0)">).</span><span style="color:rgb(112,61,170)">startIndex</span></b></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><b><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> range = startIndex..&lt;str1.</span><span style="color:rgb(112,61,170)">endIndex</span></b></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">    range.</span><span style="color:rgb(112,61,170)">startIndex</span><span style=""> = range.</span><span style="color:rgb(112,61,170)">startIndex</span><span style="">.</span><span style="color:rgb(61,29,129)">advancedBy</span><span style="">(</span><span style="color:rgb(39,42,216)">10</span><span style="">)</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">}</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style=""><br></span></p><p style="margin:0px;line-height:normal"><font face="georgia, serif">If you encounter this issue, you need to use rangeOfComposedCharacterSequenceAtIndex to update to hidden endIndex.</font></p><p style="margin:0px;line-height:normal"><font face="georgia, serif"><br></font></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">do</span><span style=""> {</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> str = </span><span style="color:rgb(209,47,27)">&quot;abcdefg&quot;</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(187,44,162)">var</span><span style=""> range = str.</span><span style="color:rgb(112,61,170)">startIndex</span><span style="">..&lt;str.</span><span style="color:rgb(112,61,170)">endIndex</span><span style=""> </span><span style="color:rgb(0,132,0)">// 0..&lt;7</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    str += </span><span style="color:rgb(209,47,27)">&quot;hijklmn&quot;</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="">//    range.endIndex = str.endIndex // 0..&lt;14</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    <b>range = str.</b></span><b><span style="color:rgb(112,61,170)">startIndex</span><span style="">..&lt;str.</span><span style="color:rgb(112,61,170)">endIndex</span></b></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">    </span><span style="color:rgb(187,44,162)">let</span><span style=""> index = range.</span><span style="color:rgb(112,61,170)">startIndex</span><span style="">.</span><span style="color:rgb(61,29,129)">advancedBy</span><span style="">(</span><span style="color:rgb(39,42,216)">10</span><span style="">)</span></p><p style="margin:0px;line-height:normal">






</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">}</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""><br></span></p><p style="margin:0px;line-height:normal"><font face="georgia, serif">Reassign the whole range instead of just set the endIndex.</font></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style=""><br></span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="">Zhaoxin</span></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 18, 2016 at 10:14 AM, zh ao <span dir="ltr">&lt;<a href="mailto:owenzx@gmail.com" target="_blank">owenzx@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I just make a clearer example.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><span class=""><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="color:rgb(187,44,162)">do</span><span> {</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span>    </span><span style="color:rgb(187,44,162)">var</span><span> str = </span><span style="color:rgb(209,47,27)">&quot;abcdefg&quot;</span></p>
</span><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span>    </span><span style="color:rgb(187,44,162)">var</span><span> str1 = str + </span><span style="color:rgb(209,47,27)">&quot;hijklmn&quot;</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span>    </span><span style="color:rgb(187,44,162)">var</span><span> range = str.</span><span style="color:rgb(112,61,170)">startIndex</span><span>..&lt;str1.</span><span style="color:rgb(112,61,170)">endIndex</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span>    range.</span><span style="color:rgb(112,61,170)">startIndex</span><span> = range.</span><span style="color:rgb(112,61,170)">startIndex</span><span>.</span><span style="color:rgb(61,29,129)">advancedBy</span><span>(</span><span style="color:rgb(39,42,216)">10</span><span>)</span></p><span class="">
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span>//fatal error: cannot increment endIndex</span></p>
<p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span>}</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span><br></span></p></span><p style="margin:0px;line-height:normal"><font face="georgia, serif">It seams that </font><font face="Menlo"><span style="font-size:11px">range.</span></font><span style="font-family:georgia,serif">startIndex internally contains a fault endIndex(str.endIndex, it should be its own endIndex, range.endIndex), which leads the issue.</span></p><p style="margin:0px;line-height:normal"><font face="georgia, serif"><br></font></p><p style="margin:0px;line-height:normal"><font face="georgia, serif">Zhaoxin</font></p></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 18, 2016 at 12:02 AM, Dmitri Gribenko <span dir="ltr">&lt;<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Tue, May 17, 2016 at 5:46 AM, zh ao via swift-users<br>
&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:<br>
&gt; It seams that I encountered bugs in function advancedBy().<br>
&gt;<br>
</span><span>&gt; do {<br>
&gt;     var str = &quot;abcdefg&quot;<br>
&gt;     var range = str.startIndex..&lt;str.endIndex // 0..&lt;7<br>
&gt;     str += &quot;hijklmn&quot;<br>
&gt;     range.endIndex = str.endIndex // 0..&lt;14<br>
&gt;     let index = range.startIndex.advancedBy(10)<br>
&gt;     //fatal error: cannot increment endIndex<br>
&gt; }<br>
<br>
</span>Hi,<br>
<br>
Thank you for the report.  To me, this issue looks the same as<br>
<a href="https://bugs.swift.org/browse/SR-1487" rel="noreferrer" target="_blank">https://bugs.swift.org/browse/SR-1487</a>.<br>
<span><font color="#888888"><br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf(&quot;%d\n&quot;,i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>&gt;*/<br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>