Swift Program to Create an Enumeration With the Specific Type and Access Its Raw Value

You are currently viewing Swift Program to Create an Enumeration With the Specific Type and Access Its Raw Value

Swift program to create an enumeration with the specific type and access its raw value

// Swift program to create enumeration with
// the specific type and access its raw value

import Swift

enum Colors:Int {
    case RED    = 1
    case GREEN
    case BLUE
    case WHITE
}

enum Countries:String {
    case IN    = "India"
    case US    = "United State of America"
    case AU    = "Australia"
}

print("Colors: ",Colors.RED.rawValue,Colors.GREEN.rawValue,Colors.BLUE.rawValue,Colors.WHITE.rawValue)

print("Countries: ",Countries.IN.rawValue,",",Countries.US.rawValue,",",Countries.AU.rawValue)

Output

Colors:  1 2 3 4
Countries:  India , United State of America , Australia

...Program finished with exit code 0
Press ENTER to exit console.

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply