0Pricing
Swift Academy · Lesson

Enumeration

Enumeration

Enumeration is a free Swift Academy lesson on CoddyKit — lesson 1 of 1. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 1 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Introduction

Hello,

In this lesson, we will learn the subject of Enumeration.

Enumeration is used to create user-defined types. In the next step, working with this user-defined associated data allows us to write code with high type security.

Enums are types of value used to hold data belonging to a related group together. It allows us to work with type security in codes.

cont.

There is some information we need to know about enums. Let's list them.

  • In Swift, every casein in my enum does not have to have a value.
  • The raw values ​​assigned to the casings in the enum can be a String, Character, integer, or floating-point type.
  • We can define AssociatedValue in Enum. These defined values ​​can be of any type.
  • It is a first-class type in Enumeration Swift.

cont.

  • We do not have to define value, ie raw Value, for each of the casings in the enumeration. Enumerations are first-class types. We can adapt property, method, or initializer,
  • Enumerations can be implemented by implementing protocols and writing extensions.
  • Enumeration names must start with a capital letter.
  • Enumerations are value types, they are not reference types.
enum SiliconValley {
case Google
case Apple
case Microsoft
}

enum SiliconValley1 { case Apple, Google, Amazon, Microsoft} 

var companyName = SiliconValley1.Apple 
companyName = SiliconValley1 . Google 
companyName = .Amazon 

/*
After the first definition, he realized that the 
variable companyName type is the SiliconValley1 enum.
As in the .Amazon definition in the last line, 
there is no need to pass the name of the enum as an extra.
companyName is automatically inferred.
*/

rawValue

Raw value can also be defined in our enums.

Let's learn on the example.

enum Direction1: String { 
case North, South, East, West
 }


//Default value of North = “North” 
//Default value of South = “South” 
//Default value of East = “East”
//Default value of West = “West”

enum SiliconValley2: Int {
 case Apple, Google, Amazon, Microsoft
}
 //Default value of Apple = 0, Google =1, Amazon =2 , Microsoft =3

example

Now, let's explicitly illustrate the Raw Value Ancestor.

enum Direction2: Character
 { 
case North = "n" 
case South = "s" 
case East = "e" 
case West = "w"
}

enum SiliconValley3: Int { 
case Apple = 1 , Google, Amazon, Microsoft 
}
 // value of Google = 2, Amazon = 3, Microsoft = 4



// Defined Enum Raw Value can be accessed as follows.
enum SiliconValley4: Int { case Apple = 1 , Google, Microsoft, Amazon }
let companyRank = SiliconValley4.Amazon.rawValue 

print ( "Raw value of Amazon is \(companyRank)" ) 
//Prints Raw value of Amazon is 4”

Congratulations

Congratulations 🎉

In this lesson, we learned Enumeration on Swift.

See you in the next lesson.

Enumeration — illustration 6

Frequently asked questions

Is the “Enumeration” lesson free?

Yes — the full text of “Enumeration” is free to read here on the web, and the Swift Academy course includes 1 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.

What will I learn in “Enumeration”?

Enumeration You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Swift Academy?

No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 1, so you can start here or from the beginning and move at your own pace.

How long does the “Enumeration” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Swift Academy lesson?

Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

← Back to Swift Academy