I'm pulling my hair out trying to generate a valid NSRange, it doesn't seem like it should be this complicated so I'm guessing I'm using the wrong approach. Here is what I'm trying to do:
I have a string with some unicode character in it:
"The quick brown fox\n❄jumped\n❄over the lazy dog"
let start = text.rangeOfString("❄")?.startIndex
NSMakeRange(start, text.endIndex - start)
Cast your String as NSString.
You will be able to use Foundation's
.rangeOfString instead of Swift's
The Foundation's one will return an NSRange.
Be careful though, it doesn't work the same as Swift's method with Unicode, and NSRange and Range are not compatible (although there's ways to convert them).