A concise, runnable example of Swift enumerations — plain cases and associated values.
Enumerations in Swift define a common type for a group of related values, letting you work with those values in a type-safe way. This repository is a small, self-contained Xcode Playground that demonstrates the two building blocks of Swift enums: defining an enum with simple cases and declaring cases that carry associated values. It is meant as a concise learning reference you can open and run in seconds.
- Declaring a basic
enumwith simple cases and reading one of them into a constant. - Defining an enum whose cases carry associated values (
StringandInt). - Creating an instance by passing a value into a case with a named associated value.
- Runnable inside an iOS Xcode Playground with no additional setup.
git clone https://github.com/ahmetbostanciklioglu/Enums.git
cd EnumsUnzip Enum.playground.zip, open Enum.playground in Xcode, and run the playground to see the results in the sidebar.
- Xcode 12 or later
- Swift 5
- iOS Playground target
Ahmet Bostancıklıoğlu — @ahmetbostanciklioglu · ahmetbostancikli@gmail.com
⭐ If this helped you, consider giving the repo a star!