序列的协议(protocol)
是一个 Swift 协议(protocol),所以它是必需的所有方法。
看一下它的声明,我现在看到有很多方法,比如
makeIterator(), map(), filter()
等等……
我想知道为什么只
makeIterator()
方法是必需的。
它不是带有可选关键字的@objc 协议(protocol),它不是协议(protocol)的扩展,它不符合任何其他协议(protocol)。这是一种简单的 Swift 协议(protocol)。
有什么想法吗?
最佳答案
关于问题,Hamish给我们正确的解决方案
it's not a protocol's extension" – No, Sequence does provide default implementations for the rest of its requirements, e.g map's default implementation is here, filter's default implementation is here. Note that there's also a default implementation for makeIterator() when the sequence is its own iterator.
我们可以找到makeIterator()
默认实现here
非常感谢!
关于swift - 序列的协议(protocol)所需方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45508841/