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
Action Steps
- Define an enum to represent a group of related values using the 'enum' keyword
- Use cases to specify the different values of the enum, such as 'case north' or 'case south'
- Initialize an enum variable using the dot notation, like 'let direction: CompassPoint = .east'
- Use a switch statement to handle different cases of the enum, such as 'switch direction { case .north: print("North") }'
- 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)
[](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
1 Add reaction
1 Like 0 Unicorn 0 Exploding Head 0 Raised Hands 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)
[](https://dev.to/tohemt)
[Theo Millard](https://dev.to/tohemt)
Posted on Jun 2, 2025
1
# 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
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)
[](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
1 Add reaction
1 Like 0 Unicorn 0 Exploding Head 0 Raised Hands 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)
[](https://dev.to/tohemt)
[Theo Millard](https://dev.to/tohemt)
Posted on Jun 2, 2025
1
# 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
DeepCamp AI