Lesson 15 - Enums and custom errors in Swift
In the previous lesson, Handling errors in Swift, we learned how to use methods which can
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
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...
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
- Unlimited and permanent access to individual lessons.
- High quality IT knowledge.
- Skills to help you get your dream and well-paid job.
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.