Skip to content
KnowledgeCity

Swift Intermediate: Enumerations in Swift

Establish programming methods involved in Swift enumerations.
Preview the first lesson free — get full access to all 5 lessons.
Course: On-Demand
Intermediate Provider Mark Nair  5 Lessons ·  35m  in Arabic, German, English, Spanish, French, Portuguese, Chinese 

Course Description

In this module, you’ll learn about Enumerations, or enums, which define a type for a group of related values. For example, you might create an enum for a direction that would include all the related values of up, down, left, right. When you need to access the values for direction, you’ll be able see all these pre-set values and use them in a type-safe way through your code.

You’ll learn the syntax of enums and how to use switch to find the right case for your logic. Switching is a technique you can use to control the flow of logic in your program. Using switch with enums is a standard practice of evaluating and navigating these related values.

You’ll also learn how to make your enums more descriptive with associated values and how use an enum’s raw value. You’ll also learn about the protocol CaseIterable, which can make an array of every case in your enum, and you’ll learn how to make and use recursive enumerations.

What You'll Learn

  • Identify enumeration syntax in Swift
  • Use switch statements to match the correct enum case and control program flow
  • Describe associated values and raw values for enums
  • Apply the CaseIterable protocol to produce an array of every case in an enum
  • Create and use recursive enumerations

Key Takeaways

  • Enumerations (enums) define a type for a group of related values, such as a direction with the values up, down, left, and right.
  • Enums let you access pre-set values and use them in a type-safe way throughout your code.
  • Using switch with enums is a standard practice for evaluating and navigating related values and controlling the flow of logic in a program.
  • Associated values make enums more descriptive, and enums can also use a raw value.
  • The CaseIterable protocol can make an array of every case in an enum, and recursive enumerations can be created and used.

Frequently Asked Questions

What does this Swift module cover?

This module covers enumerations (enums) in Swift: enum syntax, using switch to find the right case for your logic, associated values, raw values, the CaseIterable protocol, and recursive enumerations.

What are enumerations used for in Swift?

Enumerations define a type for a group of related values, for example a direction that includes the related values up, down, left, and right, letting you access these pre-set values and use them in a type-safe way through your code.

What lessons are included in this course?

The course includes the lessons Enumeration Syntax, Associated Values, Raw Values, Using CaseIterable, and Recursive Enumerations.

What skills does this course help develop?

It helps develop skills in enums, function modules, functional programming, object code, programming concepts, and the Swift programming language.

How are switch statements used with enums in this course?

You learn to use switch to find the right case for your logic; switching controls the flow of logic in your program, and using switch with enums is a standard practice for evaluating and navigating related values.