gpt4 book ai didi

swift - 类型 `String.index (aka` string.CharacterView.index`) 不符合协议(protocol)`_Strideable`

转载 作者:行者123 更新时间:2023-11-30 12:06:34 24 4
gpt4 key购买 nike

我得到类型String.index(又名string.CharacterView.index)不符合协议(protocol)_Strideable

problem code picture

如何解决这个问题?

最佳答案

我不知道为什么String.Index不是_Strideable ,但是这段代码实际上没有意义。

  • stringRangeRange<String.CharacterView.Index>? ,它将测量字素簇。
  • NSRegularExpression期待 NSString ,由UTF-16代码单元组成。

充其量,你很幸运,它们是相同的,而且这只是一种计算长度的慢得多的方法。最坏的情况是,它将正则表达式应用于以代码点中间结尾的子字符串。

你应该这样做:

let range = NSRange(location: 0, length: self.utf16.count)

关于swift - 类型 `String.index (aka` string.CharacterView.index`) 不符合协议(protocol)`_Strideable`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46617820/

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