swift - CountableRange的startIndex和lowerBound有什么区别?

标签 swift collections range

Documentation says :

The associated Bound type is both the element and index type of CountableRange. Each element of the range is its own corresponding index. The lower bound of a CountableRange instance is its start index, and the upper bound is its end index.

var lowerBound: Bound { get } 已声明

var lowerBound: Bound
The range's lower bound.

In an empty range, lowerBound is equal to upperBound.

Declaration
var lowerBound: Bound { get }

var startIndex: Bound { get } 已声明

var startIndex: Bound
The position of the first element in a nonempty collection.

If the collection is empty, startIndex is equal to endIndex.

Declaration
var startIndex: Bound { get }

这两者之间有什么区别吗?我如何决定使用哪一个?

最佳答案

lowerBoundstartIndex 对于 CountableRange 来说是完全等价的,upperBoundendIndex,如文档所述:

The lower bound of a CountableRange instance is its start index, and the upper bound is its end index.

CountableRange 提供这两个属性的唯一原因是 startIndex and endIndex are required by the Collection protocollowerBound and upperBound are common to all Range types (即:CountableRange、CountableClosedRange 等)。

关于swift - CountableRange的startIndex和lowerBound有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43768859/

相关文章:

ios - 每次将新的 tableViewCell 添加到 UITableView 时如何调用函数

Android List<T> 等价物

ios - 当时间改变时改变 UIPickerView 的内容?

wpf - 接口(interface)/抽象的 XAML 集合 "Could not create an instance"

c# - 在 C# 中,按 DateTime 排序的最佳方法是什么?最后有空的吗?

excel - 从用户选择中获取多个范围 (Excel VBA)

php - 为第 1 行的 'id' 列调整的超出范围值

javascript - 通过javascript更改宽度时输入范围的奇怪行为

ios - Swift - 从数组中读取

swift - 在 Swift 中终止应用程序时调用函数