Properties in protocols
You can also define properties in a protocol:
protocol VehicleProperties { var weight: Int { get }
var name: String { get set }
}
When defining properties in a protocol, you must explicitly mark them as get and/or set, somewhat similar to the way you declare computed properties. However, much like methods, you don’t include any implementation for properties. Are you starting to see a pattern here? :]
The fact that you must mark get and set on properties shows that a protocol doesn’t know about a property’s implementation, which means it makes no assumption about the property’s storage. You can then implement these properties as computed properties or as regular variables. All the protocol requires is that the property is either readable, if it has only a get requirement, or readable and writable, if it has both a get and a set requirement.
Even if the property has only a get requirement, you’re still allowed to implement it as a stored property or a read-write computed property, as the requirements in the protocol are only minimum requirements. Your conforming type must have at least the functionality required by the protocol.