The enumeration in Swift is also known as enum
. Enums are user-defined data types with a fixed set of related values.
enum NameOfEnum{case value}
NameOfEnum
: This is the name we want to give to our enum.value
: This represents the value we want to give to our enum. This could be more than one.An enumeration is returned with a set of related values.
import Swift// create some enumerationsenum Colors {case REDcase GREENcase BLUE}enum Fruits {case MANGO, PINEAPPLE, ORANGE}enum Seasons {case WINTER, SPRING, AUTUMN, SUMMER}// Print the enumerations createdprint("The Primary colors are: ", Colors.RED,Colors.GREEN,Colors.BLUE)print("Some fruits we know are:", Fruits.MANGO,Fruits.PINEAPPLE,Fruits.MANGO)print("Some seasons are :", Seasons.WINTER, Seasons.AUTUMN, Seasons.SUMMER, Seasons.SPRING)
enum
to the console.