一个简单而建立一个正确的方式
NSRange从
Range<String.Index>是使用它的初始化:
public init<R, S>(_ region: R, in target: S) where R : Rangeexpression, S : StringProtocol, R.Bound == String.Index
在您的情况下:
if let range = text.range(of: host) { return NSRange(range, in: text)}


