Computed Properties vs Property Requirements - protocol

In addition to stored properties, classes, structures, and enumerations can define computed properties, which do not actually store a value. Instead, they provide a getter and an optional setter to retrieve and set other properties and values indirectly.

A protocol can require any conforming type to provide an instance property or type property with a particular name and type. The protocol doesn’t specify whether the property should be a stored property or a computed property—it only specifies the required property name and type. The protocol also specifies whether each property must be gettable or gettable and settable.

https://docs.swift.org/swift-book/LanguageGuide/Properties.html

 

猜你喜欢

转载自www.cnblogs.com/feng9exe/p/9642539.html