Swift Basics: Enums

📰 Dev.to · Theo Millard

Learn the basics of enums in Swift and how to use them to define a common type for related values

beginner Published 2 Jun 2025
Action Steps
  1. Define an enum to represent a group of related values using the 'enum' keyword
  2. Use cases to specify the different values of the enum, such as 'case north' or 'case south'
  3. Initialize an enum variable using the dot notation, like 'let direction: CompassPoint = .east'
  4. Use a switch statement to handle different cases of the enum, such as 'switch direction { case .north: print("North") }'
  5. Apply enums to real-world scenarios, such as representing compass points or error types
Who Needs to Know This

This lesson is beneficial for iOS developers and software engineers who want to improve their Swift programming skills, especially those working on projects that require type-safe code

Key Insight

💡 Enums in Swift enable type-safe code and improve readability by defining a common type for related values

Share This
📚 Learn Swift enums basics! Define a common type for related values and work with them in a type-safe way 🚀

Full Article

Title: Swift Basics: Enums

URL Source: https://dev.to/tohemt/swift-basics-enums-3ffc

Published Time: 2025-06-02T02:20:50Z

Markdown Content:
[Skip to content](https://dev.to/tohemt/swift-basics-enums-3ffc#main-content)

[![Image 1: DEV Community](https://media2.dev.to/dynamic/image/quality=100/https://dev-to-uploads.s3.amazonaws.com/uploads/logos/resized_logo_UQww2soKuUsjaOGNB38o.png)](https://dev.to/)

[Powered by Algolia](https://www.algolia.com/developers/?utm_source=devto&utm_medium=referral)

[Log in](https://dev.to/enter?signup_subforem=1)[Create account](https://dev.to/enter?signup_subforem=1&state=new-user)

## DEV Community

![Image 2](https://assets.dev.to/assets/heart-plus-active-9ea3b22f2bc311281db911d416166c5f430636e76b15cd5df6b3b841d830eefa.svg)1 Add reaction

![Image 3](https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg)1 Like ![Image 4](https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg)0 Unicorn ![Image 5](https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg)0 Exploding Head ![Image 6](https://assets.dev.to/assets/raised-hands-74b2099fd66a39f2d7eed9305ee0f4553df0eb7b4f11b01b6b1b499973048fe5.svg)0 Raised Hands ![Image 7](https://assets.dev.to/assets/fire-f60e7a582391810302117f987b22a8ef04a2fe0df7e3258a5f49332df1cec71e.svg)0 Fire

0 Jump to Comments 0 Save Boost

Copy link

Copied to Clipboard

[Share to X](https://twitter.com/intent/tweet?text=%22Swift%20Basics%3A%20Enums%22%20by%20Theo%20Millard%20%23DEVCommunity%20https%3A%2F%2Fdev.to%2Ftohemt%2Fswift-basics-enums-3ffc)[Share to LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fdev.to%2Ftohemt%2Fswift-basics-enums-3ffc&title=Swift%20Basics%3A%20Enums&summary=An%20enumeration%20defines%20a%20common%20type%20for%20a%20group%20of%20related%20values%20and%20enables%20you%20to%20work%20with...&source=DEV%20Community)[Share to Facebook](https://www.facebook.com/sharer.php?u=https%3A%2F%2Fdev.to%2Ftohemt%2Fswift-basics-enums-3ffc)[Share to Mastodon](https://s2f.kytta.dev/?text=https%3A%2F%2Fdev.to%2Ftohemt%2Fswift-basics-enums-3ffc)

[Share Post via...](https://dev.to/tohemt/swift-basics-enums-3ffc#)[Report Abuse](https://dev.to/report-abuse)

[![Image 8: Theo Millard](https://media2.dev.to/dynamic/image/width=50,height=50,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2123160%2F081c2919-4d37-4eb7-b7bc-3cdc280aa0b8.png)](https://dev.to/tohemt)

[Theo Millard](https://dev.to/tohemt)
Posted on Jun 2, 2025

![Image 9](https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg)1![Image 10](https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg)![Image 11](https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg)![Image 12](https://assets.dev.to/assets/raised-hands-74b2099fd66a39f2d7eed9305ee0f4553df0eb7b4f11b01b6b1b499973048fe5.svg)![Image 13](https://assets.dev.to/assets/fire-f60e7a582391810302117f987b22a8ef04a2fe0df7e3258a5f49332df1cec71e.svg)

# Swift Basics: Enums

[#swift](https://dev.to/t/swift)[#enums](https://dev.to/t/enums)[#errors](https://dev.to/t/errors)

> An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe way within your code.

## [](https://dev.to/tohemt/swift-basics-enums-3ffc#basic-enum-example) Basic Enum Example

```
enum CompassPoint {
case north
case south
case east
case west
}

// Initiation can be done like this
let currentState = CompassPoint.east

// or like this
let direction:CompassPoint = .east
```

## [](https://dev.to/tohemt/swift-basics-enums-3ffc#switch-in-enum) Switch in Enum

```
switch directionToH
Read full article → ← Back to Reads