0Pricing
Swift Academy · Lesson

Computed Properties in Structs

Deriving values with get-only and get/set computed properties.

Welcome

Computed properties don't store a value — they compute and return one on demand. They look like properties to callers but run code under the hood.

Read-Only Computed Property

```swift struct Circle { var radius: Double var area: Double { .pi * radius * radius } var circumference: Double { 2 * .pi * radius } } var c = Circle(radius: 5) print(c.area) // 78.53... ```

All lessons in this course

  1. Memberwise Initializers and Custom Inits
  2. Stored Properties and Property Observers
  3. Computed Properties in Structs
  4. Mutating Methods and Copy-on-Write Semantics
← Back to Swift Academy