Swift — Enums
Basic enum
enum Direction {
case north, south, east, west
}
let dir = Direction.north
Raw values
enum Planet: Int {
case mercury = 1, venus, earth
}
let earth = Planet.earth.rawValue // 3
Associated values
enum Barcode {
case upc(Int)
case qrCode(String)
}
Mini Practice
- Create enum
- Use raw values
- Add associated values
- Practice switch
Up Next
Continue with Extensions - Extension syntax.
Related Topics
Frequently Asked Questions about Enums
What is Enums in Swift?
Enums is a fundamental concept in Swift. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Enums?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Enums.
Why is Enums important in Swift?
Enums is essential for Swift development. Understanding this concept will help you write better code and solve real-world problems more effectively.