Complete the code to declare an enum named Direction.
enum [1] {
case north
case south
case east
case west
}The enum name should be Direction to follow Swift naming conventions.
Complete the code to create a variable with the enum value east.
var currentDirection: Direction = Direction.[1]Enum cases in Swift start with lowercase by convention. The case is east as per the enum declaration.
Fix the error in the switch statement to handle all enum cases.
switch currentDirection {
case .north:
print("Going north")
case .south:
print("Going south")
case [1]:
print("Going east")
default:
print("Unknown direction")
}The missing case is .east to cover the east direction in the switch.
Fill both blanks to create an enum with associated values and assign it.
enum Barcode {
case upc(Int, Int, Int, Int)
case qrCode(String)
}
var productBarcode = Barcode.[1]([2])The enum case upc takes four integer values as associated values.
Fill all three blanks to create a recursive enum and use it.
indirect enum ArithmeticExpression {
case number(Int)
case addition([1], [2])
case multiplication([3], ArithmeticExpression)
}
let five = ArithmeticExpression.number(5)The recursive enum uses ArithmeticExpression as the type for its associated values.
