Data Enum
Enumerated data that holds only one of a predefined set of values
2 min read
A Data Enum is a data type that can hold only one of a predefined set of values. For example, a to-do's priority must be one of low, medium, or high, and an order status can only be one of fixed values like pending, paid, or shipped.
Restricting the range of values prevents invalid values from being entered and also makes choosing a value more convenient.
Creating an Enum
In the Data Scheme sidebar, you can create an Enum alongside a regular Schema. An Enum consists of the following.
- name — e.g.
Priority - baseType — the base type of the values.
stringorinteger - list of members — the allowed entries. e.g.
low,medium,high
Beyond its display name, each member can optionally carry two more things.
- Value — what actually gets stored and sent. If omitted, the name (string) or the position (integer) is used. e.g. name
Night, valuedark. - Image (Symbol) — an SF Symbol icon, shown alongside the member in menus and buttons.
Using an Enum in a field
Choose enum as a Schema field's type and assign the Enum you created. That field can then hold only the values defined in the Enum.
When editing the data value, a Picker appears instead of free input, so you can only choose from the defined values. When serialized to JSON, the value is stored as a string or a number depending on the baseType.
Connecting an Enum to controls
Enum fields plug straight into selection UI — the items come from the Enum automatically, and the user's choice is written back to the data.
- Menus — connect a Button's or Bar Button's menu to an Enum: the members become menu items, the current value shows a checkmark, and the button's title and image follow the selected member. Menus support nested submenus of any depth.
- Segmented Control — member names become the segments; picking one writes that member's value back to the data (two-way).
Common choices like the camera's position, aspect ratio, and flash ship as built-in enums.
When you import OpenAPI/Swagger or a JSON Schema, the enumerations defined in the spec are automatically created as Data Enums. Identical sets of values are consolidated into one with no duplicates.