Complete the code to define an enum named Direction.
enum Direction {
case [1]
case south
case east
case west
}The enum Direction should have a case named north to represent the four main directions.
Complete the switch statement to handle the Direction enum.
func describe(direction: Direction) -> String {
switch direction {
case [1]:
return "Going north"
default:
return "Other direction"
}
}The switch case should match the north case of the Direction enum to return the correct description.
Fix the error in the switch statement to correctly match the enum cases.
func action(for direction: Direction) -> String { switch direction { case .[1]: return "Move up" case .south: return "Move down" default: return "Stay still" } }
The enum case should be north to match the Direction enum. Using up causes an error because it is not defined.
Fill both blanks to create a switch that returns a message for east and west directions.
func directionMessage(_ dir: Direction) -> String {
switch dir {
case .[1]:
return "Heading east"
case .[2]:
return "Heading west"
default:
return "Unknown direction"
}
}The switch cases should be east and west to return the correct messages for those directions.
Fill all three blanks to create a switch that returns a message for north, south, and other directions.
func travelAdvice(_ direction: Direction) -> String {
switch direction {
case .[1]:
return "Go forward"
case .[2]:
return "Go backward"
default:
return "Stay put"
}
}
let dir = Direction.[3]
print(travelAdvice(dir))dir that is not handled explicitly in the switch.The switch cases should be north and south to return the correct advice. The variable dir is set to north to test the function.