ADVERTISEMENT
ADVERTISEMENT

Swift program to demonstrate the enumeration

Here, we are going to demonstrate the enumeration in Swift programming language.
Submitted by Nidhi, on July 09, 2021

Problem Solution:

Here, we will create two enumerations using the enum keyword and print their values on the console screen.

Program/Source Code:

The source code to demonstrate enumeration is given below. The given program is compiled and executed successfully.

// Swift program to demonstrate enum

import Swift

enum Colors {
    case RED
    case GREEN
    case BLUE
    case WHITE
}

enum Fruits {
    case MANGO, APPLE, BANANA, PAYAYA
}

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

print("Fruits: ",Fruits.MANGO,Fruits.APPLE,Fruits.BANANA,Fruits.PAYAYA)

Output:

Colors:  RED GREEN BLUE WHITE
Fruits:  MANGO APPLE BANANA PAYAYA

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

Explanation:

In the above program, we imported a package Swift to use the print() function using the below statement,

import Swift

Here, we created two enumerations Colors, Fruits. In the Colors enumeration, we created each constant with a different case keyword. While we create constants using a single case in Fruits enumeration. After that, we printed the values of enumeration constants on the console screen.

Swift Enum Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.