本文介绍了在Swift中需要澄清Typealias语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的示例中,有人可以解释为什么在类型别名 Generator之后有一个:吗?是说 Generator符合 GeneratorType吗?我很困惑,因为当我阅读Swift文档时,它仅在别名之后描述一个 =符号。

Can someone explain why there is a ":" after the typealias "Generator" in the example below? Is it saying that "Generator" is conforming to "GeneratorType"? I am confused because when I read the Swift documentation, it only describes an "=" sign after an alias name.

protocol SequenceType : _Sequence_Type {
    typealias Generator : GeneratorType
    func generate() -> Generator
}


推荐答案

在协议中, typealias 声明一个。符合该协议的类和结构必须具有 typealias 指令,该指令将类型声明为具体的东西。

In a protocol, typealias declares an associated type. Classes and structures that conform to this protocol must have a typealias directive that declares the type to something concrete.

是,这意味着 Generator SequenceType GeneratorType c $ c>协议。

Yes, it means that Generator must conform to GeneratorType in any implementation of the SequenceType protocol.

这篇关于在Swift中需要澄清Typealias语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 15:48