加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在斯威夫特,什么是“进步”?

发布时间:2020-12-14 05:36:07 所属栏目:百科 来源:网络整理
导读:根据“ Swift语言指南”的 Control Flow部分, The for-in loop performs a set of statements for each item in a range,sequence,collection,or progression. 我很确定我知道其中三个是: 范围:用range operators,…或…定义的东西. 顺序:符合SequenceTyp
根据“ Swift语言指南”的 Control Flow部分,

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.

第一次提到,除了for-in文档之外,我看到“进展”是在定义了步幅方法的快速框架的评论中.
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 than end.

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 to end. Note:: There is no guarantee that end is an element of the sequence.

所以简而言之,“进展”是指Strideable协议类似于“收集”是指CollectionType协议以及符合它的类和结构体.

数字类型(Int,Double,Float,UnsafePointer,Bit等)倾向于符合该协议,因此它们可以在循环中递增/递减.完整的继承图为Strideable协议发现here.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读