且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法为类型“Range"调用初始化程序带有类型为 '(start: String.Index, end: String.Index)' 的参数列表

更新时间:2022-06-22 22:26:31

Range.init(start:end:) 构造函数在 Swift 3.0 中被移除,所以你可以像下面这样初始化一个范围:

Range.init(start:end:) constructor was removed in Swift 3.0 so you initialize a range like follows:

let range = hex.index(hex.startIndex, offsetBy: 2)..<hex.index(hex.startIndex, offsetBy: 4)

它返回一个 half-open 类型的 范围.然后,您可以使用它执行以下操作:

which returns a half-open range of type <String.Index>. Then, you can do the following with that:

hex.substring(with: range)