Get up to 80 % extra points for free! More info:

Lesson 15 - Enums and custom errors in Swift

In the previous lesson, Handling errors in Swift, we learned how to use methods which can raise an Error. There are several variants of try-catch blocks to do this.

In today's Swift tutorial, we're going to explain enumerated types, enums, and how to define our own error states - own Errors.


It's nothing complicated. Enums represent a list of possible values of a variable. It's useful, especially when storing an object's state which can be one of only a few values. If we stored the individual values as Strings, nobody could guarantee they only contain the defined values and we could make a mistake. We can only store one of the predefined values to an enum type variable.

Days of the week are a typical example of enum usage, just as well as e.g.


...End of the preview...
Continue further

You will gain knowledge worth hundreds of thousands for a few crowns

You've come here and that's great! We believe that the first lessons showed you something new and useful
Do you want to continue the course? Go to the premium section.

Buy this course

Buy all currently available lessons with exercise submitting and other features for just $5.76
Current account balance $0
By buying this package, you'll have access to all 16 articles (16 lessons) in this course.

This article is licensed: Premium II, by buying this article, you agree with the terms of use.

What will you get from us in the next lessons?
  • Unlimited and permanent access to individual lessons.
  • High quality IT knowledge.
  • Skills to help you get your dream and well-paid job.

Article description

Requested article covers this content:

In this Swift tutorial, we'll learn to use enums, the enumerated types. It'll be followed by creating and handling custom Errors.

You gain credits by supporting our network. This is done by sending a helpful amount of money to support the site, or by creating content for the network.

Article has been written for you by Filip Němeček