Complete the code to declare an enum with raw values of type String.
enum Direction: String {
case north = [1]
case south = "South"
}The raw value for the case must be a String literal, so it needs to be in double quotes.
Complete the code to declare an enum with raw values of type Int starting at 1.
enum Weekday: Int {
case monday = [1]
case tuesday
}Raw values of type Int must be integers. To start at 1, assign monday = 1.
Fix the error in the enum raw value declaration.
enum Color: String {
case red = [1]
case blue = "Blue"
}Raw values of type String must be enclosed in double quotes. Using "Red" is correct.
Fill both blanks to create an enum with raw values and access a raw value.
enum Planet: Int {
case earth = [1]
case mars = [2]
}
let marsValue = Planet.mars.rawValueAssign earth = 2 and mars = 3 to set raw values correctly.
Fill all three blanks to create an enum with raw values and a function returning a raw value.
enum Status: String {
case success = [1]
case failure = [2]
case unknown = [3]
}
func getStatusMessage(_ status: Status) -> String {
return status.rawValue
}Each case must have a string raw value in double quotes matching the case meaning.
