<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 22. Sep 2017, at 23:55, Ben Cohen &lt;<a href="mailto:ben_cohen@apple.com" class="">ben_cohen@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">In order to be able to use pos… this function would need to be converted from it’s current signature (that takes a concrete Range) to be generic over any RangeExpression.In this case of this method, the range is optional – and in case of nil (which is the default) there would be insufficient context to determine the actual type of the RangeExpression. So we’d need to have an overload instead.<div class=""><div class=""><br class=""><div class="">But none of this ought to be necessary, because constant time slicing and index sharing means we don’t need to have functions take optional range arguments any more. Instead you can just write str[pos...].range(of: “f”).&nbsp;</div></div></div></div></div></blockquote><div><br class=""></div><div>That makes sense.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><div class=""><br class=""></div><div class="">Except... this technique has a bug in it for this particular method when used on substrings, that we need to fix before that can be used instead. Hoping for that to be fixed on master soon...<br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>Good to know!</div><div><br class=""></div><div>Regards, Martin</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Sep 21, 2017, at 2:44 AM, Martin R 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=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">The&nbsp;range(of:options:range:locale:) method of StringProtocol does not accept a partial range as search range. Example (Xcode 9, Swift 4):<br class=""><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp;&nbsp;<span style="color: #ba2da2" class="">let</span> str = <span style="color: #d12f1b" class="">"foo"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">le</span><span style="text-decoration: underline ; color: #ba2da2" class="">t</span> pos = str.<span style="color: #703daa" class="">startIndex</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">let</span> r = str.range(of: <span style="color: #d12f1b" class="">"f"</span>, range: pos...)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class="">&nbsp; &nbsp; </span>// error: cannot convert value of type 'PartialRangeFrom&lt;String.Index&gt;'</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class="">&nbsp; &nbsp; </span>// to expected argument type 'Range&lt;String.Index&gt;?'</div></div><div class=""><br class=""></div><div class="">Is that because it is an NSString method imported to Swift? Would it make sense to file an enhancement request?</div><div class=""><br class=""></div><div class="">Regards, Martin</div><div class=""><br class=""></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=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></div></blockquote></div><br class=""></body></html>