How to use swift enums?
Example:
enum Direction {
case north, south, east, west
}
var dir = Direction.north
Enums are used to define a type with a limited set of possible values. Above, we defined a 'Direction' enum.
Solution:
switch dir {
case .north:
print("Going up!")
case .south:
print("Going down!")
default:
print("Moving around")
}
This demonstrates how to use a switch case with the enum to handle different directions.