gpt4 book ai didi

swift - '子字符串(到 : )' is deprecated: Please use String slicing subscript with a ' partial range upto' operator

转载 作者:IT王子 更新时间:2023-10-29 05:33:17 26 4
gpt4 key购买 nike

如何将以下代码更新到新版本的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com