distance(from:to:)’ is unavailable: Any String vIEw index conversion can fail in Swift 4; please unwrap the optional indices
func nsRange(from range: Range<String.Index>) -> NSRange { let utf16vIEw = self.utf16 let from = range.lowerBound.same@R_419_4612@(in: utf16vIEw) let to = range.upperBound.same@R_419_4612@(in: utf16vIEw) return NSMakeRange(utf16vIEw.distance(from: utf16vIEw.startIndex,to: from),// Error: distance(from:to:)' is unavailable: Any String vIEw index conversion can fail in Swift 4; please unwrap the optional indices utf16vIEw.distance(from: from,to: to))// Error: distance(from:to:)' is unavailable: Any String vIEw index conversion can fail in Swift 4; please unwrap the optional indices}你可以简单地打开这样的可选索引:
func nsRange(from range: Range<String.Index>) -> NSRange? { let utf16vIEw = self.utf16 if let from = range.lowerBound.same@R_419_4612@(in: utf16vIEw),let to = range.upperBound.same@R_419_4612@(in: utf16vIEw) { return NSMakeRange(utf16vIEw.distance(from: utf16vIEw.startIndex,utf16vIEw.distance(from: from,to: to)) } return nil}总结
以上是内存溢出为你收集整理的distance(from:to :)’不可用:任何String视图索引转换都可能在Swift 4中失败;请打开可选索引全部内容,希望文章能够帮你解决distance(from:to :)’不可用:任何String视图索引转换都可能在Swift 4中失败;请打开可选索引所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)