count是集合中的项目数,而endIndex是刚刚超过集合结尾的
Index
(from the Indexable
protocol).
对于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","d" slice.startIndex // 1 slice.count // 3 slice.endIndex // 4