So I've found issues relating to the case of converting NSRange
to Range<String.Index>
, but I've actually run into the opposite problem.
Quite simply, I have a String
and a Range<String.Index>
and need to convert the latter into an NSRange
for use with an older function.
So far my only workaround has been to grab a substring instead like so:
func foo(theString: String, inRange: Range<String.Index>?) -> Bool {
let theSubString = (nil == inRange) ? theString : theString.substringWithRange(inRange!)
return olderFunction(theSubString, NSMakeRange(0, countElements(theSubString)))
}
This works of course, but it isn't very pretty, I'd much rather avoid having to grab a sub-string and just use the range itself somehow, is this possible?