Enums are used to create a collection of related constants representing a type. For example, you might use an Enum to represent the days of the week (i.e., "DaysOfWeek": Sunday, Monday, Tuesday).

Enums prevent invalid values from being assigned. For example, if you have an enum for days of the week, you can't mistakenly assign a non-existent day. In contrast, with strings or numbers, you might accidentally use an invalid or misspelled value like "Sundey" or "Sinday".

Here are some real-world examples where using Enums is beneficial:

  1. Application States: A media player might use enums to keep track of playback states (e.g., PLAYING, PAUSED, STOPPED).

  2. Product Types, Sizes, or Categories: A clothing store app might use enums to categorize clothing sizes (SMALL, MEDIUM, LARGE).

  3. Order or Process Status: For tracking the status of orders, processes, or tasks (PENDING, IN_PROGRESS, COMPLETED, CANCELED).

Create and use Enums

Let's see how you can create and use Enums in your app.

  1. Select Data Types from the left side Navigation Menu.

  2. Switch to Enums tab and click on the + button.

  3. A popup will open. Enter the Enum name and click Create.

  4. Click on the + Add Value and provide the enum values.

  1. To get a list of enums, you can access via Set from Variable menu > Enums > [your enum name] > Values.

  1. To use enums for comparison, access via Set from Variable menu > [your enum name] > [enum value]. Below is an example of displaying a chart based on the "UserRole" enum value.

Published Date: December 1, 2023

Last updated