Static in Swift Protocols

In « The Swift Programming Language (Swift 3). », they start Protocol chapter with this example :

protocol SomeProtocol {
    var mustBeSettable: Int { get set }
    var doesNotNeedToBeSettable: Int { get }
}


Then, they make a statement contradicting this example :


« Always prefix type property requirements with the static keyword when you define them in a protocol. This rule pertains even though type property requirements can be prefixed with the class or static keyword when implemented by a class: »


With the following example

protocol AnotherProtocol {
    static var someTypeProperty: Int { get set }
}


But 2 lines later, they give another example without static :

Here’s an example of a protocol with a single instance property requirement:

protocol FullyNamed {
    var fullName: String { get }
}


So, is static compulsory ? Is it compulsory only when property is settable ? What is the consequence not including static keyword ?

Or do they simply mean to use static and not class keyword.

Answered by QuinceyMorris in 232931022

>> Or do they simply mean to use static and not class keyword.


That. The sentence you quoted says "Always prefix type property requirements…", meaning non-instance (class or static) properties.


It's unfortunate that the word "type" is so generic in English that it's ambiguous in this context.

Accepted Answer

>> Or do they simply mean to use static and not class keyword.


That. The sentence you quoted says "Always prefix type property requirements…", meaning non-instance (class or static) properties.


It's unfortunate that the word "type" is so generic in English that it's ambiguous in this context.

Thanks for that quick clarification.

Static in Swift Protocols
 
 
Q