A concise, runnable Swift Playground exploring computed and stored properties.
Properties associate values with a particular class, struct, or enum. Swift distinguishes between stored properties, which hold a constant or variable value as part of an instance, and computed properties, which calculate a value each time they are accessed rather than storing it.
This is a small, self-contained Xcode Playground that demonstrates both kinds side by side. It is meant as a quick, runnable learning example rather than a full application.
- Computed property β a
varbacked by a getter block that returns a value on access instead of storing one. - Stored property β a plain
vardeclared inside astructthat holds its value as part of the instance. - Creating an instance of a struct and passing an initial value to its stored property via the memberwise initializer.
git clone https://github.com/ahmetbostanciklioglu/Properties.git
cd PropertiesUnzip Properties.playground.zip, open Properties.playground in Xcode, and run the playground to see the results appear in the sidebar.
- Xcode 12 or later
- Swift 5
Ahmet BostancΔ±klΔ±oΔlu β @ahmetbostanciklioglu Β· ahmetbostancikli@gmail.com
β If this helped you, consider giving the repo a star!