endIndex 返回与 count 相同的值。
这是正确的行为还是错误?
var ar = [1, 2, 3, 4]
ar.count // 4
ar.endIndex // 4
count
是集合中的项目数,而endIndex
is the Index(来自Collection协议) https://developer.apple.com/documentation/swift/collection/index这刚刚过去了该系列的结尾。
For Array
,这些是相同的。对于其他一些集合,例如ArraySlice
, 他们不是:
let array = ["a", "b", "c", "d", "e"]
array.startIndex // 0
array.count // 5
array.endIndex // 5
let slice = array[1..<4] // elements are "b", "c", "d"
slice.startIndex // 1
slice.count // 3
slice.endIndex // 4
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)