文档 说:
关联的绑定类型是可计数范围的元素和索引类型。范围的每个元素都是其自己的相应索引。CountableRange 实例的下限是其起始索引,上限是其结束索引。
声明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 }
这两者之间有什么区别吗,我如何决定使用哪一个?
lowerBound
和startIndex
对于一个CountableRange
是完全等价的,就像upperBound
和endIndex
一样,如文档所述:
CountableRange 实例的下限是其起始索引,上限是其结束索引。
CountableRange
提供这两个属性的唯一原因是Collection
协议需要startIndex
和endIndex
,而lowerBound
和upperBound
是所有范围类型(即:CountableRange,CountableClosedRange等)共有的。