I have this String
category:
extension String {
subscript (i: Int) -> String {
return self[Range(i ..< i + 1)]
}
subscript (r: Range<Int>) -> String {
let range = Range(uncheckedBounds: (lower: max(0, min(count, r.lowerBound)),
upper: min(count, max(0, r.upperBound))))
let start = index(startIndex, offsetBy: range.lowerBound)
let end = index(start, offsetBy: range.upperBound - range.lowerBound)
return String(self[start ..< end])
}
}
and Xcode is giving me a warning at this line:
return self[Range(i ..< i + 1)]
'init' is deprecated: CountableRange is now Range. No need to convert any more.
It's a shame that even though I'm quite well experienced with Swift, I have no idea how to fix this. Question is: how to get rid of this warning.
Thank you!
You don't need the Range.init
. In other words, change:
return self[Range(i ..< i + 1)]
to:
return self[i ..< i + 1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With