The properties we’ve seen in previous lessons are instance properties, since they’re associated with an instance of a given type. Each instance can store a different value, such as different Square
instances storing different sideLength
values:
</div> language-'></div>">Properties can also be associated with a type itself. These are known as **type properties**, and they only maintain a single value per type. This behavior makes type properties good for storing values that are ubiquitous amongst all instances of a type. A type property is denoted by the **static** keyword:
<div class='oc-markdown-activatable oc-markdown-custom-container' data-value='```swift
struct Square {
static let sides = 4
}
'>
Type properties are set and accessed from the type itself using dot syntax:
Type properties can be stored or computed just like instance properties. Stored type properties must have a default value since types themselves aren’t initialized.