gpt4 book ai didi

swift - 如何比较 Range 和 DefaultBidirectionalIndices

转载 作者:搜寻专家 更新时间:2023-10-31 22:05:52 24 4
gpt4 key购买 nike

此比较在 Swift 2 中有效,但在 Swift 3 中无效:

让 myStringContainsOnlyOneCharacter = mySting.rangeOfComposedCharacterSequence(at: myString.startIndex) == mySting.characters.indices

如何比较 Range 和 DefaultBidirectionalIndices?

最佳答案

来自 SE-0065 – A New Model for Collections and Indices

In Swift 2, collection.indices returned a Range<Index>, but because a range is a simple pair of indices and indices can no longer be advanced on their own, Range<Index> is no longer iterable.

In order to keep code like the above working, Collection has acquired an associated Indices type that is always iterable, ...

rangeOfComposedCharacterSequence返回一个范围字符索引,解决方案是使用indices , 但 startIndex..<endIndex :

myString.rangeOfComposedCharacterSequence(at: myString.startIndex) 
== myString.startIndex..<myString.endIndex

关于swift - 如何比较 Range<String.Index> 和 DefaultBidirectionalIndices<String.CharacterView>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39533523/

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