Swift Program to Compare Enumeration Constants Based on Raw Values

You are currently viewing Swift Program to Compare Enumeration Constants Based on Raw Values

Swift program to compare enumeration constants based on raw values

// Swift program to compare enumeration constants
// based on raw values

import Swift

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

var cl = Colors(rawValue: 2)

if(cl == Colors.GREEN)
{
    print("Matched")
}
else
{
    print("Not Matched")
}

Output

Matched

...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