Merge pull request #222 from zhousak/gh-pages
协议章节中关于类属性和类方法的定义描述不达意,理解有困难
This commit is contained in:
@ -67,8 +67,7 @@ protocol SomeProtocol {
|
||||
}
|
||||
```
|
||||
|
||||
用类来实现协议时,使用`class`关键字来表示该属性为类成员;用结构体或枚举实现协议时,则使用`static`关键字来表示:
|
||||
|
||||
在协议中定义类属性 (type property)时使用`class`前缀关键字,即使在结构体或者枚举中类属性是要求使用`static`前缀关键字:
|
||||
```swift
|
||||
protocol AnotherProtocol {
|
||||
class var someTypeProperty: Int { get set }
|
||||
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user