【发布时间】:2017-03-26 04:36:30
【问题描述】:
我在https://github.com/github/swift-style-guide/blob/master/README.md阅读了以下建议
但这部分我不明白。接收类型是什么,接收器是什么? 谢谢。
尽可能省略类型参数
参数化类型的方法可以省略类型参数 接收类型与接收者相同时。例如:
struct Composite<T> { … func compose(other: Composite<T>) -> Composite<T> { return Composite<T>(self, other) } }可以呈现为:
struct Composite<T> { … func compose(other: Composite) -> Composite { return Composite(self, other) } }
【问题讨论】:
-
比较Swift: Declaration in generic class & What is the cause of this type error?——
Composite在Composite<T>范围内的类型被推断为Composite<T>。