The
for-in
loop performs a set of statements for each item in a range,sequence,collection,or progression.
我很确定我知道其中三个是:
>范围:用range operators,…或…定义的东西.
>顺序:符合SequenceType协议(文档没有任何明显的,但各种人都有reverse-engineered)
> collection:Swift collection types,即Array和Dictionary
(我注意到#3可能是多余的,因为数组和字典似乎都符合SequenceType.)
但是什么是“进步”?这是第四件事情,还是作者只是用文字?
ETA:我看到有一个CollectionType协议,所以解释#3.
func stride<T : Strideable>(from start: T,to end: T,by stride: T.Stride) -> StrideTo<T>
Return the sequence of values (
start
,start + stride
,start + stride + stride
,… last) where last is the last value in the progression that is less thanend
.
func stride<T : Strideable>(from start: T,through end: T,by stride: T.Stride) -> StrideThrough<T>
Return the sequence of values (
start
,… last) where last is the last value in the progression less than or equal toend
. Note:: There is no guarantee thatend
is an element of the sequence.
所以简而言之,“进展”是指Strideable协议类似于“收集”是指CollectionType协议以及符合它的类和结构体.
数字类型(Int,Double,Float,UnsafePointer,Bit等)倾向于符合该协议,因此它们可以在循环中递增/递减.完整的继承图为Strideable协议发现here.