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 }
这两者之间有什么区别吗?我如何决定使用哪一个?
最佳答案
lowerBound
和 startIndex
对于 CountableRange
来说是完全等价的,upperBound
和 endIndex
,如文档所述:
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
protocol而lowerBound
and upperBound
are common to all Range types (即:CountableRange、CountableClosedRange 等)。
关于swift - CountableRange的startIndex和lowerBound有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43768859/