A concise, runnable playground showing how self disambiguates properties inside initializers.
In Swift, self refers to the current instance of a type. It is most often used inside an initializer or method to distinguish a stored property from a parameter that shares the same name. This repository is a concise, runnable learning example β a single Xcode Playground (Self.playground) that demonstrates the pattern with two small struct examples.
- Using
self.property = propertyinside aninitto resolve the naming collision between a stored property and an initializer parameter. - A minimal struct with one property assigned through a custom initializer.
- A struct that mixes an injected property with a default-valued property, initializing only the injected one.
- Watching Swift's Playground evaluate each expression and show its value inline.
git clone https://github.com/ahmetbostanciklioglu/Self.git
cd Self
unzip Self.playground.zip
open Self.playgroundOpen the playground in Xcode and let it execute β the results sidebar shows each expression's value as it runs.
- macOS with Xcode 13 or later
- Swift 5+
Ahmet BostancΔ±klΔ±oΔlu β @ahmetbostanciklioglu Β· ahmetbostancikli@gmail.com
β If this helped you, consider giving the repo a star!