String.Index(utf16offset:in:)
should do the trick (assuming that all offsets are valid for the string and do not refer to a position in the middle of a UTF-16 surrogate pair):
let from = String.Index(utf16Offset: startByteOffset / 2, in: stringValue)
let to = String.Index(utf16Offset: endByteOffset / 2, in: stringValue)
let rangeToHighlight = from..<to
This initializer was introduced in swift-evolution/proposals/0241-string-index-explicit-encoding-offset.md at main · apple/swift-evolution · GitHub.
I do not know what happens if the range encloses a single low or high surrogate, and how such a situation could be detected. As I understand it from [Accepted] SE-0241: Explicit Encoded Offsets for String Indices, this is considered a programmer error.