Enumerations

Enumerations define a named set of accepted string values for parameters in action definitions and functions.

Table of Contents

  1. Syntax
  2. Using Enums in Action Definitions
  3. Function Arguments
  4. Quantity Enumerations
  5. Standard Library Enums

Syntax

enum typeName {
    'Option1',
    'Option2'
}

Each value is raw text (single quoted string). A trailing comma after the last value is allowed. The braces may also be on the same line as the name:

enum Colors {'Red', 'Green', 'Blue'}

An enumeration must be declared before the definition that uses it.

Using Enums in Action Definitions

When an action parameter has an enum type, only the declared values are accepted.

enum Color {
    'Red',
    'Green',
    'Blue',
}

action 'com.example.app.paint' paint(Color color: 'WFColor')

paint("Purple") // throws an error

Function Arguments

Function parameters accept enum types in the same way. Quantity enumerations are not supported in functions.

enum Color {
    'Red',
    'Green',
}

function describe(Color color): text {
    output("Color: {@color}")
}

describe("Purple") // throws an error

Quantity Enumerations

Quantity enumerations are only supported in action definitions, not functions. Prefix an enum type with # to make the argument a quantity field value, with the enum values as the units:

enum Durations {
    'sec',
    'min',
    'hr'
}

action 'com.example.app.action' myCustomAction(#Durations duration: 'WFDuration' = qty(0, "sec"))

Standard Library Enums

The standard library action pages show the enum definition inline alongside each action that uses one. These enums are defined inside the Cherri compiler - you do not need to define them yourself when using standard library actions.

For example, from the Crypto actions:

enum hashType {
    'MD5',
    'SHA1',
    'SHA256',
    'SHA512',
}

hash(variable input, hashType ?type = "MD5"): text

When calling hash(), pass one of the declared string values as the argument:

#include 'actions/crypto'

@input = "Hello, Cherri!"
const result = hash(@input, "SHA256")

Copyright ©. Distributed under the GPL-2.0 License. Siri Shortcuts and Mac are registered trademarks of Apple Inc. Apple is not involved in this project in any way. Do not contact Apple Support unless you are having an issue with the Shortcuts app itself.