![](/img/trans.png)
[英]Cannot invoke 'append' with an argument list of type '(Range<String.Index>)'
[英]Cannot invoke initializer for type 'Range<String.Index>' with an argument list of type '(start: String.Index, end: String.Index)'
let greenHex = hex.substring(with: Range<String.Index>(start: hex.index(hex.startIndex, offsetBy: 2), end: hex.index(hex.startIndex, offsetBy: 4)))
这是Swift3.0,hex是一个字符串,但是这段代码抛出一个错误,说:
无法使用类型为'(start:String.Index,end:String.Index)的参数列表调用类型'Range'的初始化程序
在Swift 3.0中删除了Range.init(start:end:)
构造函数,因此您初始化如下的范围:
let range = hex.index(hex.startIndex, offsetBy: 2)..<hex.index(hex.startIndex, offsetBy: 4)
返回类型<String.Index>
的半开放范围。 然后,您可以执行以下操作:
hex.substring(with: range)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.