Reusable actions
Name a list of steps once, in Data & Logic, and run it from any view with Run Action.
A reusable action is a list of steps with a name. You keep it in Data & Logic, and any view runs it with the Run Action step. A Sign in button and the password field's Return key can share the same sign-in steps, and when you change them, both get the change.
#Make one
- In the Library (the left panel), open Data & Logic (the last tab, or ⌘5).
- Under Reusable actions, tap New action. A new, empty action named newAction opens.
- Tap Add action to add steps. They work the same as in a view's Actions tab: tap a step to open it, touch and hold it to move or remove it. See How steps run.
- Tap Done.
The top of the sheet reminds you: "Runs these steps in order wherever “Run Action → newAction” is used."
#Rename, edit or delete one
Each reusable action has a card under Reusable actions, with its steps in short, like "Set Value · Try · Set Value".
- Rename: tap its name and type a new one. Every Run Action that runs it follows the new name. A name keeps only letters, numbers and _, and it can't be empty or the same as another action's.
- Edit: tap Edit steps (Add steps while it has none).
- Delete: tap its trash button. It's deleted right away; Undo (⌘Z) brings it back.
#Run one from a view
- Select the view and open the Inspector's Actions tab.
- Pick the When, then tap Add action and choose Run Action (under Logic).
- Open the step and pick the reusable action in Action.
The button next to Action (Edit or create a reusable action) has two shortcuts:
- Edit “signIn” opens the picked action's steps.
- New Reusable Action makes a new action, picks it in this step and opens it, so you can add its steps right away.
Run Action works anywhere a step can go: inside an If, a Try, a Show Alert button, or another reusable action.
#Pass values in
Run Action's With sends values to the action, like which note to delete.
- In the Run Action step, under With, tap Add field.
- Name the field, like
noteID, and give it a value. Use ⚡︎ to link it to app data or a formula. - In the reusable action's steps, read the value as
params.noteID, like Where:it.id == params.noteIDin a Remove from List.
#How it runs
The action's steps run right where its Run Action is, as part of the same run, with the same rules: in order, one at a time, each slow step waited for. When they finish, the steps after Run Action carry on.
- A step that fails inside the action stops the whole run, unless something is catching it. Put the Run Action, or the steps inside the action, in a Try.
- Stop inside the action ends the whole run, not only the action.
- In Preview's debugger, the action's steps show under its Run Action, indented.
- On the Flow board, the action's own steps aren't drawn. What they did in the last run counts for the Run Action step.