我正在查看SequenceType
的协议声明,并且我想知道如何理解generate
是SequenceType
派生的类的唯一函数应该实现。
public protocol SequenceType {
/// A type that provides the *sequence*'s iteration interface and
/// encapsulates its iteration state.
typealias Generator : GeneratorType
/// A type that represents a subsequence of some of the elements.
typealias SubSequence
/// Return a *generator* over the elements of this *sequence*.
///
/// - Complexity: O(1).
@warn_unused_result
public func generate() -> Self.Generator
/// Return a value less than or equal to the number of elements in
/// `self`, **nondestructively**.
///
/// - Complexity: O(N).
@warn_unused_result
public func underestimateCount() -> Int
/// Return an `Array` containing the results of mapping `transform`
/// over `self`.
///
/// - Complexity: O(N).
@warn_unused_result
@rethrows public func map<T>(@noescape transform: (Self.Generator.Element) throws -> T) rethrows -> [T]
我实现了一个派生自SequenceType
的自定义类,在我添加对generate的支持之前,我收到了以下错误:
键入&#39; MySequenceClass&#39;不符合协议&#39; SequenceType&#39;
查看标题声明,我认为我必须实现此协议的所有方法,但显然我不是。阅读这些标题文档的诀窍是什么?