On page 369 of the book The Swift Programming Language, it says “Always prefix type property requirements with the static keyword when you define them in a protocol.”
Example Code:
protocol AnotherProtocol {
static var someTypeProperty: Int { get set }
}
What is the reason or benefit of doing so?
Because without the static
keyword you end up declaring an instance property rather than a type property. The example that immediately follows the paragraph you quote shows this:
Here’s an example of a protocol with a single instance property requirement:
protocol FullyNamed { var fullName: String { get } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With