The Shortcuts app in iOS transforms an iPhone into an automated workflow engine. While basic shortcuts run linear step-by-step actions, advanced shortcuts rely on programmatic control flow—specifically conditional logic (If statements), custom variables, and nested evaluation blocks. By introducing conditional branching, your shortcuts can dynamically respond to battery levels, current locations, network SSIDs, or user input dialogues.
Understanding Logic Actions in Apple Shortcuts
Shortcuts treats actions as data-processing blocks where output values can be passed forward or evaluated against Boolean conditions:
- If Block: Tests whether an input condition evaluates to true or false. It automatically creates an enclosed action container divided into two execution paths: If [Condition] and Otherwise.
- Otherwise: The fallback branch that executes whenever the initial condition criteria are not met.
- End If: The boundary marker terminating the conditional branch. Actions placed after End If run regardless of which branch was executed.
- Variables: Data containers that store text, numbers, dates, dictionary objects, or device states. Shortcuts supports automatic Magic Variables, manual Set Variable blocks, and Add to Variable arrays.
Setting Up an “If” Conditional Action
To demonstrate conditional logic, consider an automation that checks whether your iPhone is connected to your home Wi-Fi network before triggering an action:
- Open the Shortcuts app on your iPhone and tap the + (Add) button in the top-right corner to create a new shortcut.
- Tap the bottom search bar, type
Get Network Details, and tap to insert the action into the canvas. - Ensure the action is configured to Get [Wi-Fi Network Name].
- In the action search bar, type
Ifand tap the If (Scripting) action. - The shortcut builder automatically links the network output to the condition: If Network Details [Condition].
- Tap the condition selector (which may say is, contains, or has any value) and choose is.
- Tap the text field and enter the exact SSID name of your home Wi-Fi network.
Building the Conditional Execution Branches
Now insert the respective tasks into the If and Otherwise containers:
- Search for
Show NotificationorShow Alert. Drag the action block directly underneath the If Network Details is [YourNetwork] line so it is visually indented inside the first branch. - Set the message text to:
Connected to Home Network. Ready to sync. - Search for another
Show Alertaction. Drag this second block directly underneath the Otherwise divider line. - Set the message text to:
Away from home. Connecting to VPN... - Tap the Play button in the bottom-right corner of the screen to run and test the shortcut logic.
Working with Custom Variables and Calculations
While Magic Variables automatically pipe the output of one step into another, explicit named variables are required when dealing with counters, loops, or complex multi-step data manipulation.
| Variable Action | Operation | Example Use Case |
|---|---|---|
| Set Variable | Assigns a specific value or input item to a named variable name, overwriting existing contents. | Capturing a calculated total or user input string at the start of a flow. |
| Add to Variable | Appends values to an existing named variable, creating a multi-item list or array. | Collecting multiple selected photos, file names, or URLs during batch operations. |
| Calculate / Scripting | Applies mathematical operations (+, -, ×, ÷) to numerical variables. | Calculating tip percentages, split bill amounts, or time offsets in minutes. |
Tips for Debugging Complex Shortcut Flows
As conditional trees grow deeper with nested If statements, errors can occur when data types mismatch:
- Inspect Variable Types: Long-press a variable pill inside an action and tap Type. Ensure Shortcuts interprets the data as the expected type (e.g. Number rather than Text) so numerical comparison operators like is greater than appear in conditional dropdowns.
- Use Quick Look for Debugging: Place a Quick Look action immediately preceding an If statement during testing to preview the exact value and payload structure being evaluated.
- Default Values for Empty Inputs: If a variable might return null (such as location services temporarily unavailable), use the If [Variable] has any value condition to prevent runtime execution aborts.