宣布关联的Bound类型是CountableRange的元素和索引类型。范围的每个元素都是其自己的对应索引。 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 }
这两者之间有什么区别,我该如何决定使用哪一个?
答案 0 :(得分:5)
lowerBound
和startIndex
完全等同于CountableRange
,upperBound
和endIndex
也是如此,如文档中所述:
CountableRange实例的下限是其起始索引,上限是其结束索引。
CountableRange
提供这两个属性的唯一原因是startIndex
and endIndex
are required by the Collection
protocol而lowerBound
and upperBound
are common to all Range types(即:CountableRange,CountableClosedRange等)。