如何将以下代码更新到新版本的 swift:
self.areaCodeLael.text! = localNumber.substring(to: localNumber.index(localNumber.startIndex, offsetBy: 3))
我试过关注这篇文章,但我做对了 How can I use String slicing subscripts in Swift 4?
我将我的原始代码调整为 localNumber[..<3]
但我得到:
Cannot subscript a value of type 'String' with an index of type 'PartialRangeUpTo'
最佳答案
在这种情况下,我会说 localNumber.prefix(3)
。简短而甜美。
关于swift - '子字符串(到 : )' is deprecated: Please use String slicing subscript with a ' partial range upto' operator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45922857/