How steps run
Build a view's steps in the Actions tab, and learn what happens when they run: in order, waiting, failing and stopping.
Steps are what your app does when something happens. You build them in the Inspector's Actions tab: pick a When (the trigger), then add steps under Do, in order. This page shows how to build them and how they run.
#Build steps in the Actions tab
- Select a view on the canvas.
- In the Inspector, tap Actions (or press ⌘⌥2).
- The card at the top shows WHEN and the current trigger, like Tapped. Tap it to pick another one. See Triggers.
- Tap Add action. Add Action opens with every action, grouped by category. Type in Search actions to find one, then tap it. It's added at the end of the list.
- Tap the new step to open it, and fill in its settings.
A new step starts with some required settings filled in: one of your variables, another screen, 1 for a number, true for a condition. Change them to what you need, and fill in the rest. Until a required setting is filled in, the issue count in the toolbar lists it as an error, like “Show Message needs its text.”, and errors stop Preview and Finish.
An open step shows what the action does, then one row per setting. Each row has an ⓘ that explains it. Text and number settings also have ⚡︎, to link the setting to a variable or a formula instead of typing a fixed value. Text with {braces} reads values, like Saved {name}. Tap the step's title again to close it.
#Move, copy or remove a step
Touch and hold a step for Move Up, Move Down, Duplicate and Remove. An open step also has Remove at its bottom.
To remove every step of the current When at once, tap the WHEN card and choose Remove These Actions.
#Steps inside steps
Some actions hold steps of their own. Open the step and use the Add action inside each list:
| Action | Its lists of steps |
|---|---|
| If | Then, Else |
| Repeat for Each | Do |
| Try | Do, Catch |
| Animate | Do |
| Start Timer | Do |
| Open as Sheet | On Dismiss |
| Show Alert | One list under each button in Buttons |
To use the same steps in several places, make them a reusable action and run it with Run Action.
#When steps run
Steps run only when the app runs: in Preview, and when you open it from My Apps. On the canvas nothing runs, so you can tap and edit freely.
#In order, one at a time
Steps run from top to bottom. Each one finishes before the next one starts. A step that changes a variable changes it right away: everything that shows the variable updates, and the next step reads the new value.
#Slow steps are waited for
Steps marked Takes time on their page, like Call API, Wait and Take Photo, finish before the next step starts. So a Call API can save an answer into a variable, and the step after it can use that answer.
When a step opens something from the iPad (the camera, the photo library, Files, the share sheet, a new calendar event or an email), the steps wait until it closes.
A few steps start something and move on without waiting:
- Show Message shows its message, and the next step runs while the message is still showing.
- Speak Text starts talking, and the next steps run while it talks.
- Start Timer starts the timer and moves on. The timer's own steps run later, every so many seconds.
- Open as Sheet opens the screen and moves on. Its On Dismiss steps run later, when the sheet closes.
#A failure stops the run
When a step fails, the steps after it don't run. A step can fail when there's no internet for Call API, when Face ID is cancelled, or when a setting points at a screen or view that isn't there. Preview shows what went wrong in a message at the top of the app, and its debugger (the ladybug button) lists the step that failed and why.
Steps that can fail say Can fail on their page. To handle a failure yourself, put those steps inside a Try. If one of them fails, Try runs its Catch steps instead, and the run carries on after the Try. Inside Catch, error.message says what went wrong. When a server answered a Call API with an error, error.status and error.body hold its answer too.
#Stopping on purpose
Stop ends the run quietly, with no message. Stop inside an If, a Try, a Show Alert button or a reusable action ends the whole run, not only the steps around it. The one exception is a timer: Stop inside Start Timer's Do ends only that round, and the timer keeps going.
Some steps that open something stop the run quietly when the person closes it without choosing anything, because the steps after them would have nothing to use: Take Photo, Scan Code, Pick Photos and Pick File. Closing Save File, Share, Add to Calendar or Write Email doesn't stop the run.
#A trigger never runs twice at once
If a When happens again while its steps are still running, the second time is skipped, and the debugger notes it. Say someone taps Send twice during a slow Call API: the order is sent once.
This counts per view and per When, so different views run their steps side by side.
#Alerts wait for an answer
Show Alert pauses the run until the person taps one of its buttons. Then that button's steps run, then the steps after Show Alert. If the alert has an Input, what was typed is saved into its variable as the alert closes, before the button's steps run.
#When Loading stops when the view goes
When Loading starts its steps when the view appears. If the view leaves the screen before they finish, for example because the person went back, the steps stop where they are. That makes it the right place to load data with Call API. If you link its Run Again When setting to a variable, the steps also start again each time that variable changes, and a run still going is stopped first.
When Pulled to Refresh keeps its spinner turning until its steps finish.
#Timers run on their own
A timer started with Start Timer runs its Do steps every so many seconds, apart from the steps that started it. It keeps going on other screens, until a Stop Timer with the same Id stops it, or until Preview closes. A step that fails inside a timer shows in the debugger, and the timer keeps going.
#See what ran
Preview's debugger lists everything in order: each trigger, each step with the values it used, each change to a variable, each answer from the web, and why a step failed. After you close Preview, Flow shows the same run on its board, step by step.