I am encountering a random crash in the NSRange
creation. Because I added a check before, I do not understand how it can happen:
let textStr = "whatever you want"
if let end = textStr.unicodeScalars.index(textStr.startIndex, offsetBy: slide.endIndex, limitedBy: textStr.endIndex){
let realEnd = textStr.unicodeScalars.index(textStr.startIndex, offsetBy: slide.endIndex)
nsRange = NSRange(start...realEnd, in: textStr)
}
slide
is an object generated by a parser and representing a portion oftextStr
.- Parser uses
textStr.unicodeScalars
for performances reasons