<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">When using subscript of `String.CharacterView`, I got an unexpected error.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="georgia, serif">fatal error: Can't form a Character from an empty String</font></blockquote><div><br></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> test() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> s = </span><span style="font-variant-ligatures:no-common-ligatures">"Original Script:"</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> cs = s.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">characters</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">// let startIndex = cs.startIndex</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> nextIndex = </span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">"Original ?"</span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures">.</span><span style="color:rgb(112,61,170);font-family:menlo;font-variant-ligatures:no-common-ligatures">characters</span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures">.</span><span style="color:rgb(112,61,170);font-family:menlo;font-variant-ligatures:no-common-ligatures">endIndex</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> nextCharacter = cs[nextIndex]</span><span style="color:rgb(0,132,0);font-family:menlo">// above error</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)">}</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<div><span style="color:rgb(49,89,93);font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures">test</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">()</span></div><div><br></div><div class="gmail_default" style="font-family:georgia,serif">However, if I chose another way to get the nextIndex. It works.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> test() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> s = </span><span style="font-variant-ligatures:no-common-ligatures">"Original Script:"</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> cs = s.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">characters</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> startIndex = cs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">startIndex</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">// let nextIndex = </span><span style="font-family:menlo">"Original ?".characters.endIndex</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> nextIndex01 = cs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">index</span><span style="font-variant-ligatures:no-common-ligatures">(startIndex, offsetBy: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">"Original ?"</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">characters</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">count</span><span style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> nextCharacter = cs[nextIndex01]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(49,89,93)"><span style="font-variant-ligatures:no-common-ligatures">test</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">()</span></p></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Further more, I compared the two `nextIndex`. They were equal.</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;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> test() {</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> s = </span><span style="font-variant-ligatures:no-common-ligatures">"Original Script:"</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> cs = s.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">characters</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> startIndex = cs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">startIndex</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> nextIndex = </span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">"Original ?"</span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures">.</span><span style="color:rgb(112,61,170);font-family:menlo;font-variant-ligatures:no-common-ligatures">characters</span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures">.</span><span style="color:rgb(112,61,170);font-family:menlo;font-variant-ligatures:no-common-ligatures">endIndex</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> nextIndex01 = cs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">index</span><span style="font-variant-ligatures:no-common-ligatures">(startIndex, offsetBy: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">"Original ?"</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">characters</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">count</span><span style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> nextCharacter = cs[nextIndex01]</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"> </span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">print</span><span style="font-variant-ligatures:no-common-ligatures">(nextIndex01 </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">==</span><span style="font-variant-ligatures:no-common-ligatures"> nextIndex) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)">// true</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(49,89,93)"><span style="font-variant-ligatures:no-common-ligatures">test</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">()</span></p><p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(49,89,93)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><br></span></p><p style="margin:0px;line-height:normal;color:rgb(49,89,93)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><font face="georgia, serif">So I wonder, is there a bug here?</font></span></p><p style="margin:0px;line-height:normal;color:rgb(49,89,93)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><font face="georgia, serif"><br></font></span></p><p style="margin:0px;line-height:normal"><span style="color:rgb(0,0,0);font-variant-ligatures:no-common-ligatures"><font face="georgia, serif">Xcode </font></span><font color="#000000" face="georgia, serif">8.2.1 (8C1002), Swift 3.0.2</font></p><p style="margin:0px;line-height:normal;color:rgb(49,89,93)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><font face="georgia, serif"><br></font></span></p><p style="margin:0px;line-height:normal;color:rgb(49,89,93)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><font face="georgia, serif">Zhaoxin</font></span></p></div></div>