In my application, I have some code to fetch the range of the host in a URL
. It looks like this:
private func rangeOfHost(text: String) -> NSRange? {
let url = URL(string: text)
if let host: String = url?.host {
if let range = text.range(of: host) {
return NSRange(
location: range.lowerBound.encodedOffset,
length: range.upperBound.encodedOffset - range.lowerBound.encodedOffset
)
}
}
return nil
}
Xcode has been warning me that 'encodedOffset' is deprecated: encodedOffset has been deprecated as the most common usage is incorrect. Use utf16Offset(in:) to achieve the same behavior.
. However, it's not clear to me how I can replace those encodedOffsets with these suggestions. Any ideas?