Type Safely

Type Safely

Extending enum to safely loop between cases

Daily Coding Tip 005

Type Safely's avatar
Type Safely
Dec 23, 2020
∙ Paid

Although an enumeration is not an array, it is sometimes necessary to iterate over the cases that it contains. In my enumeration I have the names of three fruits: apple, banana and pear. My enum conforms to the CaseIterable protocol, and this allows me to have access to an array of my cases.

What if I want to change from my current case to the next case…

User's avatar

Continue reading this post for free, courtesy of Type Safely.

Or purchase a paid subscription.
© 2026 Type Safely · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture