Skip to content

协议章节中关于类属性和类方法的定义描述不达意,理解有困难 #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions source/chapter2/21_Protocols.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ protocol SomeProtocol {
}
```

用类来实现协议时,使用`class`关键字来表示该属性为类成员;用结构体或枚举实现协议时,则使用`static`关键字来表示:

在协议中定义类属性 (type property)时使用`class`前缀关键字,即使在结构体或者枚举中类属性是要求使用`static`前缀关键字:
```swift
protocol AnotherProtocol {
class var someTypeProperty: Int { get set }
Expand Down Expand Up @@ -120,7 +119,7 @@ var ncc1701 = Starship(name: "Enterprise", prefix: "USS")
协议方法支持`变长参数(variadic parameter)`,不支持`默认参数(default parameter)`。

前置`class`关键字表示协议中的成员为`类成员`;当协议用于被`枚举`或`结构体`遵循时,则使用`static`关键字。如下所示:

像类属性的要求一样,协议中定义类方法时也总是使用`class`关键字,即使类方法在`枚举`或`结构体`中实现时要求使用`static`关键字
```swift
protocol SomeProtocol {
class func someTypeMethod()
Expand Down