<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body 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”). </div><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><br class=""><blockquote type="cite" class=""><div class="">On Sep 21, 2017, at 2:44 AM, Martin R via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> 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 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=""> <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=""> <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=""> <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=""> </span>// error: cannot convert value of type 'PartialRangeFrom<String.Index>'</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=""> </span>// to expected argument type 'Range<String.Index>?'</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="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></div></div></body></html>